1

There are 4 custom objects (starting with CO_) in the below for loop which are all inter connected and this code is working as expected. prodId is the Salesforce ID of CO_Product__c which is passed as a parameter.

String prodId = Apexpages.currentPage().getParameters().get('product');

       for (CO_List__c master : [
            SELECT name, ( select  CO__Program__c from CO__Program_Attributes__r)  FROM CO__List__c   WHERE CO_Product__c = :prodId )
            ] ) {

     //other code here
     //other code here

       }

Now I want to change this code to support multiple products. So I tried creating a set of IDs and then changing the where clause above to something like

 where  CO_Product__c in :mySetofIds  
but I get bind error

I know I can call this code block multiple times by iterating the set but was wondering if you can suggest a better way. I have tried both Set of strings and Set of Ids but no luck.

  • Are you trying to query multiple object in one query based on the ID in a set, or are you simply trying to use IN :mySetOfIDs. If the second, please post more code as it should work just fine demanding on how you have it written. The second cannot be done with SOQL but you could use SOSL potentially – Eric Oct 24 '15 at 6:13
  • Thanks for your quick response. You are right, I got it to work Set<ID> prodIds ; prodIds = new Set<ID>(); prodIds.add('XYZL000000083o1234'); prodIds.add('XYZL000000083p1235'); prodIds.add('XYZL000000083p1236'); and changed the where clause to IN :prodIds – global4g Oct 24 '15 at 7:34
  • @PrabhatKumar that is not correct syntax – Eric Oct 24 '15 at 14:41

Your Answer

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

Browse other questions tagged or ask your own question.