Can someone help me in the below scenario. Scenario: I have a list of account id's. In that list of id's i want to separate the list of id's which have contacts associated to an account and the list of id's which don't have associated contacts. --> Accids is the ids of the account. Now i want to separate the id's of account which are having associated contacts and which are not having associated contacts. For that i have written the below query.
List<Contact> co;
Set<Id> yesacc = new Set<Id>();
Set<Id> noacc = new Set<Id>();
for(Account acc : [select (select id from contacts) where id in :accids];
co = new List<Contact>();
co.addAll(acc.contacts);
if(!co.isEmpty()){
yesacc.add(acc.id);
}
else{
noacc.add(acc.id);
}
For few records it is working fine for me, as we have a limitation of subquery for fetching only 200 records. Is there any other way in achieving this without hitting the governor limit.