function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Simi Tresa AntonySimi Tresa Antony 

The result from apex class cannot be accessed - JS RemoteAction

I am trying out  JS RemoteAction with the help of Apex dev guide.
I am trying to return the result of account , but the result.id or result.name is coming as null whereas result is not null. What is the reason? Please help..

VF code
<apex:page controller="VFRemoteAction" sidebar="false">
  <head>
      <style>
          #errors{color:red;font-size:15px;font-style:bold;margin:5px; width:100%;}
      </style>
       <script>
          var getAccount = function(){
               var accountName = document.getElementById('account_name').value;
               
               Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.VFRemoteAction.getAccount}',            
               accountName,
               function(result,event){
                   if(event.status){
                      
                       document.getElementById('result').innerHTML=result.id; --> null ????????
                   }
                   else{
                       document.getElementById('errors').innerHTML="Error --> "+event.message;
                   }
               },
               {escape: true} 
               
               );
               
               
          }
        </script>
  </head>
  <body>
      <apex:pageBlock title="Javascript Remote Sample" >
          <apex:pageBlockSection title="Search for an account" columns="2">
              <div id="errors">
              </div>
              <div id="input">
                  <label>Enter the account name:</label>
                  <input type="text" name="account_name" id="account_name"/>
                  
                  <button onclick="getAccount()">Get Account</button>

              </div>
          </apex:pageBlockSection>
      </apex:pageBlock>
      <apex:outputPanel >
           <div id="result">
            
            </div>
      </apex:outputPanel>
  </body>
</apex:page>

Apex code
global with sharing class VFRemoteAction {
    
    public static Account account{get;set;}
    
    public  String accountName{get;set;}
    
    public VFRemoteAction(){
    }
    
    
    
    @RemoteAction
    global static Account  getAccount(String accountName){
      
         account = [SELECT id,name ,site FROM ACCOUNT where name=:accountName];
          return account; 

    } 
}
Best Answer chosen by Simi Tresa Antony
Stefan AbramiukStefan Abramiuk
Hi,
JS is casesensitive and APEX is not.

Use: 
document.getElementById('result').innerHTML=result.Id;

It should work.

 

All Answers

Stefan AbramiukStefan Abramiuk
Hi,
JS is casesensitive and APEX is not.

Use: 
document.getElementById('result').innerHTML=result.Id;

It should work.

 
This was selected as the best answer
Abhishek_DEOAbhishek_DEO
As Stefan mentioned, it should be "Id" insted of "id"
Simi Tresa AntonySimi Tresa Antony
Thank you Stefan and  Abhishek !!!...  That fixed it..  Was not very conscious about that ...