0

//Java Script code

function fetchRecord()
    {
       MyCustomController1.fetchRecord(handlefetchStudent); 
    }

     function handlefetchStudent(result,event){
         if(event.type == 'exception') {
              alert(event.message);
          } else {
              document.getElementById("resultDiv").innerHTML = result.toString(); 
           }
      } 

//Apex Controller Method

@RemoteAction    
    public static Student__c fetchRecord()
    {
      Student__c student=[SELECT First_Name__c,Last_Name__c,Phone__c,Email_ID__c,Lang__c
                            FROM Student__c 
                            LIMIT 1
                           ];
                RETURN student;
       }

//its Showing me

[object Object]

How to fetch and dispaly data from this result?

2

1 Answer 1

0

This is a sample code to handle javascript remoting result in your visualforce page. Modity your javascript method like this.

function fetchRecord() {

    Visualforce.remoting.Manager.invokeAction(
        '{!$RemoteAction.MyCustomController1.fetchRecord}', 
        function(result, event){
            if (event.status) {
                // Add what all fields do you need to disaply
                document.getElementById("resultDiv").innerHTML = result.Id + ' '+result.First_Name__c + ' ' +result.Last_Name__c;

            } else if (event.type === 'exception') {
                document.getElementById("resultDiv").innerHTML = 
                    event.message + "<br/>\n<pre>" + event.where + "</pre>";
            } else {
                document.getElementById("resultDiv").innerHTML = event.message;
            }
        }, 
        {escape: true}
    );
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .