2

i have a use case where we have Account record and every account has a hierarchial relationship with account itself. i need to display the related list of child accounts contacts on the master account. how can we accomplish this?

what is the relationship name to query an account itself when in hierarchy relationship?

Example: Account A- Parent , Account B-Child to A, Account C- Child to A,

How can i display (using VF) on the account A the contact records of Account B and C? Any help is highly appreciated.

  • How many levels of Accounts do you have? (1) - There is a parent plus children? or 2) There are grandparents with children and grandchildren or (3) many levels of ancestors? – cropredy Sep 15 '15 at 0:09
0

Once you have the Parent Account ID it is simple:

Here Account__c is the API name of the lookup to the parent account (change as needed) and parentAccount is the apex ID property having the ID of the parent account

Account[] childAccounts = [Select ID, (Select ID, LastName From Contacts) from Account where Account__c = :parentAccount];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.