You need to sign in to do that
Don't have an account?

How to find all Parent records which have one sort of child record and also another sort of child record?
Users need to identify all the Accounts which have one or more Opportunity children for which Status='Won' and also have one or more Opportunity children for which Status='Lost' . A report would be ideal but any easy solution would be nice. Of course I can write batchable Apex to traverse all the data but there must be a simpler way.
You can try something as below.
List<Opportunity> oppList = new List<Opportunity>([SELECT Id, Status, AccountId FROM Opportunity
WHERE Status IN ('End-Won','End-Lost')]);
Set<Id> lostAccId = new Set<Id>(); // Using SET collection for unique Ids /Non-Duplicate Ids
Set<Id> wonAccId = new Set<Id>();
// Iterating list and setting all AccountId
for(Opportunity opp : oppList){
if(opp.status == 'End-Lost'){
lostAccId.add(opp.AccountId);
}
if(opp.status == 'End-Won'){
wonAccId.add(opp.AccountId);
}
}
Hope this helps!
Thanks,
Sucharita