Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ChildAccountsContactsController(ApexPages.StandardController controller){
- Id accId = controller.getId();
- Set<Id> allChildAccount = getAllChildAccountIds(accId);
- allContactNames = new List<Contact>();
- allContactNames = [Select Id, Name, Account.Name, Account.Parent.Name, Email, Phone from Contact where AccountId in :allChildAccount];
- }
- private Set<Id> getAllChildAccountIds(Id parentAccountId){
- Set<Id> AccountIdSet = new Set<Id>();
- AccountIdSet.add(parentAccountId);
- Boolean check=true;
- do
- {
- List<Account> accIds = [select Id from Account where ParentId in:AccountIdSet And Id not in:AccountIdSet];
- if(accIds != null && accIds.size() > 0){
- for(Integer i=0; i<accIds.size(); i++){
- AccountIdSet.add(accIds[i].Id);
- }
- }
- else
- check = false;
- }while(check);
- return AccountIdSet;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement