1

Have been trying to learn Javascript Remoting since hours. I have manipulated this example to display a table of records with remoting an apex class. Following is the controller and VF.. My controller pulls all records from custom object Feedback. But i'm unable to display in VF. Please guide.

 global with sharing class AccountRemoter {

 public String accountName { get; set; }
 public Feedback__c account { get; set; }
 public AccountRemoter() { }

 @RemoteAction
 global static List<Feedback__c> getAccount(String accountName) {
 List<Feedback__c> account = [SELECT Name FROM Feedback__c ];
 return account;
 }
 }

and the Visualforce page...

 <apex:page controller="AccountRemoter">
 <script type="text/javascript">
 function getRemoteAccount() {
    var accountName = document.getElementById('acctSearch').value;

    Visualforce.remoting.Manager.invokeAction(
        '{!$RemoteAction.AccountRemoter.getAccount}',
        accountName, 
        function(result, event){
            if (event.status) {
                // Get DOM IDs for HTML and Visualforce elements like this
                document.getElementById('remoteAcctId').innerHTML = result.Id
                document.getElementById(
                    "{!$Component.block.blockSection.secondItem.acctNumEmployees}"
                    ).innerHTML = result.NumberOfEmployees;
            } else if (event.type === 'exception') {
                document.getElementById("responseErrors").innerHTML = 
                    event.message + "<br/>\n<pre>" + event.where + "</pre>";
            } else {
                document.getElementById("responseErrors").innerHTML = event.message;
            }
         }, 
         {escape: true}
     );
   }
  </script>

    <input id="acctSearch" type="text"/>
    <button onclick="getRemoteAccount()">Get Feedbacks</button>
    <div id="responseErrors"></div>

    <apex:pageBlock id="block">
    <apex:pageBlockSection id="blockSection" columns="2">
        <apex:pageBlockSectionItem id="firstItem">
            <span id="remoteAcctId"/>
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem id="secondItem">
            <apex:outputText id="acctNumEmployees"/>
        </apex:pageBlockSectionItem>
    </apex:pageBlockSection>
   </apex:pageBlock>
   </apex:page>
         

The closest to a table on click of the "Get Feedback" button, I have achieved so far with undefined results.... enter image description here

Any help will be appreciated. Thanks

UPDATE: Fields in Feedback

Client_Feedback_App__c

Description__c

Importance__c

Resolution__c

Status__c

Summary__c

2
  • Does Feedback__c contains feid "NoOfEmployees"?
    – Ashwani
    Apr 15, 2014 at 12:21
  • I'm sorry, I update the question. There is no field called "NoOfEmployees"
    – MnZ
    Apr 15, 2014 at 12:28

1 Answer 1

1

Here should be error:

result.NumberOfEmployees; // This exists in example you have copied not in your sObject

You don't have this field in custom object. Instead try any field which exists in custom object fields and query that field in SOQL also ex:

result.Name;

Just do this, replace alert(JSON.stringify(result)) with:

for(i=0;i<result.length;i++) {
     var name= result[i].Name; // Name is field api name
     alert(name)  ; // or do whatever you want with 
}
12
  • Replacing NumberOfEmployees with Name has no effect!
    – MnZ
    Apr 15, 2014 at 12:37
  • @MnZ can you alert the result like alert(result.toString());
    – Ashwani
    Apr 15, 2014 at 12:45
  • OK, I will try.
    – MnZ
    Apr 15, 2014 at 12:45
  • on adding alert(result.toString()); to the code I recieved...object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object
    – MnZ
    Apr 15, 2014 at 12:49
  • Ok. Can you alert this alert(JSON.stringify(result)); this should work
    – Ashwani
    Apr 15, 2014 at 12:54

You must log in to answer this question.

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