3

In document.ready method i am doing this

var setIds=new Array() //array of saleforce ids
$(sel).each(function() {
     setIds.push("'"+$(this).attr('id')+"'");                                                                                    
});
var myquery = "SELECT Id,Name, Body from Attachment where Id in ("+setIds+")";
alert(myquery);
result = sforce.connection.query(myquery);                                
records = result.getArray("records");
alert(records.length);

My problem is, even i am passing set of ids to the query it is just returning 1 record.

Any guess why this happening?

Thanks!

  • Hi,I tried the same but its not working.I get malformed query exception and Bind variables only allowed in apex. – Manoj Chandran Apr 29 '16 at 12:39
3

I'm not sure whether the javascript side of things has the smarts to deal with the set or not, but you could just generate the full text query yourself:

var setIds=new Array() //array of saleforce ids
var ids = '';

$(sel).each(function() {
  ids = ids + '"' + $(this).attr('id') + '",';
});

if(ids.length > 1) {
  ids.substr(0, ids.length - 1);
}
var myquery = "SELECT Id,Name, Body from Attachment where Id in (" + ids + ")";
alert(myquery);
result = sforce.connection.query(myquery);                                
records = result.getArray("records");
alert(records.length);
  • 1
    Array.prototype.join instead... but it's good. – sfdcfox Mar 30 '14 at 11:19
  • I thought there was a method for that but couldn't remember it off the top of my head last night! – Matt Lacey Mar 31 '14 at 1:05
  • @LaceySnr my code worked when i removed body column from the query, i don't know why such a behavior. – SFIntegrator Mar 31 '14 at 12:15
-1

I never used Apex AJAX Toolkit but I think You can do something like this -

var myquery = "SELECT Id,Name, Body from Attachment where Id in:setIds"; 

In Apex query you can't pass set as an argument you we have to convert it into list. but i am not sue about AJAX Toolkit.

  • I copied my query from browser console and pasted into SF developer console it worked fine there. The query is like this SELECT Id,Name, Body from Attachment where Id in ('00P11000000JrbDEAS','00P11000000JqIoEAK') – SFIntegrator Feb 28 '14 at 7:56
  • So your problem resolved? – Pramod Kumar Feb 28 '14 at 8:12
  • No, it is returning only 1 record. – SFIntegrator Feb 28 '14 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.