Soql in Vf page using sForce.connection

830    Asked by Ajit yadav in Salesforce , Asked on Apr 16, 2021

I am trying to soql in VF page. But I am not getting an result. I have verified my code.

 [removed][removed] [removed][removed] [removed][removed] [removed] function soqlQuery(){ try{ var result = sforce.connection.query("SELECT Id, Name from Account",{ onSuccess : function(result){ alert('I am in 2'); }, onFailure : function(error){ } }); }catch(e){ alert(e); } } [removed]=function(){ soqlQuery(); } [removed] 

Can anyone check and let me know what i am missing out here. what is? How sforce connect?

Answered by Abigail Abraham

sforce connect : The version of the AJAX Toolkit is in the URL. After this script executes, the toolkit is loaded and a global object, sforce. connection , is created. This object contains all of the API calls and AJAX Toolkit methods, and manages the session ID.



To get the list of records from the result You need result.getArray("records") to get the records

complete code fot the same is:

         function soqlQuery(){ try{ sforce.connection.sessionId = '{!$Api.Session_ID}'; var result = sforce.connection.query("SELECT Id, Name from Account",{ onSuccess : function(result){ alert('I am in 2'); var records = result.getArray("records"); console.log('==========records======='+records); }, onFailure : function(error){ } }); }catch(e){ alert(e); } } [removed]=function(){ soqlQuery(); }  

and check browser console.. The version of the AJAX Toolkit is in the URL. After this script executes, the toolkit is loaded and a global object, sforce. connection , is created. This object contains all of the API calls and AJAX Toolkit methods, and manages the session ID. 


Your Answer

Interviews

Parent Categories