Skip to content

Instantly share code, notes, and snippets.

@rickschmidt
Created September 2, 2019 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rickschmidt/d3e3f076030386f7f1727036111f7824 to your computer and use it in GitHub Desktop.
Save rickschmidt/d3e3f076030386f7f1727036111f7824 to your computer and use it in GitHub Desktop.
public static List<Account> getMembersForHousehold(Id householdId){
List<Id> contactIds = new List<Id>();
//collect contactIds (persons) from ACRs
for(AccountContactRelation acr : [SELECT ContactId FROM AccountContactRelation
WHERE AccountId = :householdId
AND Account.RecordTypeId =: myAccountHousholedRecordId]){
contactIds.add(acr.ContactId);
}
//collect accountId from contact
List<Id> accountIds = new List<Id>();
for(Contact con : [SELECT AccountId FROM Contact WHERE Id IN :contactIds]){
accountIds.add(con.AccountId);
}
List<Account> accounts = [SELECT Id,Name FROM Account WHERE Id IN: accountIds];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment