function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bohemianguy100bohemianguy100 

account hierarchy soql

What is the soql statement used to generate the account hierarchy view?  For example, I'd like to run a soql statement that traverses forward and backward to return a resultset of the entire account hierarchy for the account...i.e the child accounts and the parent acount and potentially, the parent of the parent, etc., because the hierarchy can be 3 or 4 levels deep.

 

How would I construct a soql statement to return the entire account hierarchy view?

 

Thanks.

wchristnywchristny

Search for "inline account hierarchy" on the AppExchange.  Force.com Labs released this free app which allows you to display the account hierarchy on a page.  You can review their logic to see how they traversed the tree.

 

TheDeckbladTheDeckblad
The Inline Account Hierarchy wouldln't pass Salesforce's code audit these days. It employs a rather sloppy infinite SOQL loop in Apex code. Does anyone know a better modern solution?