Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. public ChildAccountsContactsController(ApexPages.StandardController controller){
  2. Id accId = controller.getId();
  3. Set<Id> allChildAccount = getAllChildAccountIds(accId);
  4.  
  5. allContactNames = new List<Contact>();
  6. allContactNames = [Select Id, Name, Account.Name, Account.Parent.Name, Email, Phone from Contact where AccountId in :allChildAccount];
  7. }
  8.  
  9. private Set<Id> getAllChildAccountIds(Id parentAccountId){
  10. Set<Id> AccountIdSet = new Set<Id>();
  11. AccountIdSet.add(parentAccountId);
  12. Boolean check=true;
  13. do
  14. {
  15. List<Account> accIds = [select Id from Account where ParentId in:AccountIdSet And Id not in:AccountIdSet];
  16. if(accIds != null && accIds.size() > 0){
  17. for(Integer i=0; i<accIds.size(); i++){
  18. AccountIdSet.add(accIds[i].Id);
  19. }
  20. }
  21. else
  22. check = false;
  23. }while(check);
  24. return AccountIdSet;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement