+ Start a Discussion
kalyforminkalyformin 

Apex SOQL - IN operator

I have a SOQL query in Apex that returns a set of records for an object

 

Here is my SOQL -

 

appl__c[] lines = [Select Occupation__c, a.Advisement_Name__c From appl__c a where a.id in (: sAppInfoIds) and a.Opportunity__r.Id =: sParentOppId];

 

The sAppInfoIds contains Ids in this format  a06R0000005pTpWIAU, a06R0000005pTpaIAE. Apparently SOQL doesnt like this and says the query retruned 0 rows. However if I explicitly replace sAppInfoIds with the above Ids in the query, it works fine.

 

Is there something I'm missing?

 

Any help is appreciated.

werewolfwerewolf
You should be passing in a variable of type List<String> or List<Id> if you're resolving a list of IDs for an IN clause in Apex.  I presume you're passing in a string of comma-separated IDs.  That's your problem.
kalyforminkalyformin

Thank you! Here's what I did and it works fine now.

 

//Instantiate a Set to hold the Ids Set<Id> appInfoIds = new Set<Id>(); //Loop thru the Ids you want to include in the IN clause for(Integer i = 0; i < customobject__c.size(); i++) { sAppId = customobject__c[i].app.Id; if(sAppId <> '') { appInfoIds.add(sAppId); } }

 

And then in the SOQL

 

 

appl__c[] lines = [Select Occupation__c, a.Advisement_Name__c From appl__c a where a.id in : appInfoIds and a.Opportunity__r.Id =: sParentOppId];