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!

1
  • Hi,I tried the same but its not working.I get malformed query exception and Bind variables only allowed in apex. Apr 29, 2016 at 12:39

2 Answers 2

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);
3
  • 1
    Array.prototype.join instead... but it's good.
    – sfdcfox
    Mar 30, 2014 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, 2014 at 1:05
  • @LaceySnr my code worked when i removed body column from the query, i don't know why such a behavior. Mar 31, 2014 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.

3
  • 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') Feb 28, 2014 at 7:56
  • So your problem resolved? Feb 28, 2014 at 8:12
  • No, it is returning only 1 record. Feb 28, 2014 at 9:01

You must log in to answer this question.

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