+ Start a Discussion

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?




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.


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?