+ Start a Discussion
dkorba2k5dkorba2k5 

Dynamic SOQL

Before I go too far down this path can someone answer if this is able to be done using Dynamic SOQL.

I know I can dynamically create the SELECT string using this.  But can I bind to a set in order to reproduce the equivalent of this:
assume I've already populated a list of id's.

SELECT id FROM Account WHERE Id in :idset

How can I create that as a query string that allows the injection of the set of id's into it.
JeremyKraybillJeremyKraybill

I don't know of a way to use bindings in dynamic SOQL, but I have done what you describe by manually building an "IN" clause from a list of ID's.

Code:
String idList = '';
   
// convert to IN clause for SOQL
for (Id id : ids) {
 idList = idList + ',\'' + id + '\'';
}
idList = idList.substring(1);


 
Hope that helps.

Jeremy Kraybill

Austin, TX