You need to sign in to do that
Don't have an account?
kalyformin
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.
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];