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
PappuPappu 

How to use soql query in visualforce page javascript?

Hi All,
Below is the javascript function in my Visualforce page. 

function ownerchange(){ 
var leadrec = sforce.connection.query('select Id fom Account');
                                alert(leadrec);
}
My goal is to retreive the Sobject Id during runtime in javascript using visualforce page.

I tried sforce.connection query, but there is no luck with that. If there is any alternatice, please let me know.

Thanks!!


 
Manj_SFDCManj_SFDC
Hi Pappu, 

please refer this http://www.sfdcpoint.com/salesforce/soql-query-in-javascript-example/ it will help you for sure
Mark this as solved if this helps you
Good luck !
jane1234jane1234
HEY PAPPU TRY THIS OUT
{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")} 
try{ 
var query = "SELECT Id,Name from Account LIMIT 2"; 
var records = sforce.connection.query(query); 
var records1 = records.getArray('records'); 
alert(records);