Saturday, August 30, 2014

select query using javascript in salesforce

select query using javascript  in salesforce 

Sometimes we may need to query records in java script in salesforce. For this we can use "sforce.connection.query". Let us demo how we can query records from any object and iterate through the returned records.


In the following example we will query 10 account records and also iterate through the retured records. Create a custom button on any object and override it with a java script as below.

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}

Result = sforce.connection.query("Select Name, Id from account limit 10");
records = Result.getArray("records");

for (var i=0; i< records.length; i++) {
      var accRecord = records[i];
      log(Account Name + " -- " + accRecord.Name);
   log(Account Id + " -- " + accRecord.Id);



The returned records can be debugged using log. 









0 comments:

Post a Comment

 
| ,