You need to sign in to do that
Don't have an account?
swain 10
Please review my code logic for fetching all child and grand child account from a parent account page
Hey , this is the logic which I thought to fetch all child and grand child account(Multilevel) from a parent account page.
List<Account> acct= [Select Id , Name , Parentid from Account group by parentid];
Set<Id> Ids = new Set<Id>();
List<String> childAcctIds = [Select Id, (Select Id from ChildAccounts) from Accounts where id:=apexpages.currentpage().getparameters().get(‘id’)];
Ids.addAll(childAcctIds);
for(Account acc: acct){
if(acc.parentid != null){
List<String> allChildIds = [Select id from Account where parentid IN : Ids];
Ids.addAll(allChildIds);
}
}
List<String> oppListOfAllChild = [Select Name ,(Select Id , Name from Opportunity) from Account where Id IN : Ids];
List<Account> acct= [Select Id , Name , Parentid from Account group by parentid];
Set<Id> Ids = new Set<Id>();
List<String> childAcctIds = [Select Id, (Select Id from ChildAccounts) from Accounts where id:=apexpages.currentpage().getparameters().get(‘id’)];
Ids.addAll(childAcctIds);
for(Account acc: acct){
if(acc.parentid != null){
List<String> allChildIds = [Select id from Account where parentid IN : Ids];
Ids.addAll(allChildIds);
}
}
List<String> oppListOfAllChild = [Select Name ,(Select Id , Name from Opportunity) from Account where Id IN : Ids];
If you need child and grand child accounts you can query as below:
Thanks.
Thanks for all the reply.
I have just one confusion in all the above code ,Is there a limitation upto 3rd level child only? If yes , Is there any way to get all child , grand child , great grand child and so on upto bottom?
Thanks in advance.