I'm trying to update multiple records and then send email notification using custom list button.

For this I need to get few fields off the related list.

One option would be traverse thru the related list using getElements... function, but it might not have all the fields you need (solution is already posted).

An alternative would be a SOQL query with required fields and selected ids you get from checkboxes. A.i.:

var records = {!GETRECORDIDS($ObjectType.obj__c)}; 
var soqlQ="SELECT name FROM obj__c WHERE Id='"+records+"'"; 
var customObj = sforce.connection.query(soqlQ);
var soqlRes = customObj.getArray("records");   

The problem here is that syntax is not supported by SOQL:


Alternative would be to construct the SOQL query in a dynamic way:

SELECT name FROM obj__c WHERE id='a0OaxxxxxxxxMRDy2' or id='a0OaxxxxxxxxMRDy2'

The trouble I have is that I do not know how to do one in JavaScript.

Any help or alternative ideas are very appreciated. Thanks, ~dzh

Edit: Solution is

var records = {!GETRECORDIDS($ObjectType.obj__c)}.toString().replace(/,/g , "','"); 
var soqlQ="SELECT name FROM obj__c WHERE Id in ('"+records+"')"; 
  • Dzh- I have a request can you please add your edit as answer.. That is little bit misleading.. If you add as answer and mark as ans then other can find easily useful. Bythe way thanks your logic worked for me. :-)
    – Ratan Paul
    Commented Mar 10, 2016 at 7:00

1 Answer 1


Since you're dealing with a list of IDs, you want to use 'IN' instead of '='. The SOQL statement needs to end up looking like this

SELECT name FROM obj__c WHERE id IN ('a0OaxxxxxxxxMRDy2', 'a0OaxxxxxxxxMRDy2')

Edit by OP: it's been a while since I had the problem, but I've put this in my original post and as per Ratan's suggestion, I should mark this as accepted answer:

var records = {!GETRECORDIDS($ObjectType.obj__c)}.toString().replace(/,/g , "','"); 
var soqlQ="SELECT name FROM obj__c WHERE Id in ('"+records+"')"; 

You must log in to answer this question.

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