You need to sign in to do that
Don't have an account?
SunnyShiny
unexpected token:ContactList.id soql query
Hello
I try to query a query with ID in (list of ids)
So i have my list with ids, name ....fields.
List<objectABC> myList = [select relatedContact__r.id from objectABC];
and I need to manage limits and bulkify to create another list of contact with thus ids.
So I try >
List<Contact> lstContact = [select name, adress from contact where Id in :myList.id];
But I've got the error
Compile Error: Initial term of field expression must be a concrete SObject: LIST<objectABC>
How can I do that ?
Thanks so much for your help
Post code snippet that is causing the error, that would be easier to help you .
if you're trying to filter a soql query by the Id's of another list of objects, Apex allows you to just use that list of sObjects. It seems to be a special case. (Normally you'd have to create a list<id> variable to hold the list of Id's you want to filter on.)
so taking your example, you should be able to do the following.
List<objectABC> myList = [select relatedContact__r.id from objectABC];
List<Contact> lstContact = [select name, adress from contact where Id in :myList];
Salesforce doesn't allow you to perform Below approach :
>>
List<objectABC> myList = [select relatedContact__r.id from objectABC];
List<Contact> lstContact = [select name, adress from contact where Id in :myList.id];
For this ,we have to modify our approach as below :
>>
List<objectABC> myList = [select relatedContact__r.id from objectABC];
Set<Id> st_contact = new Set<id> ();
For(objectABC objABC :myList)
st_contact.add(objABC.relatedContact__c);
List<Contact> lstContact = [select Id,name, adress from contact where Id in :st_contact];
The reason, I have used relatedContact__c instead of relatedContact__r.id (becoz ,Lookup Id can also be retrieved by this way ) .
Warm Regards,