The Avonni Blog
Tutorial
5 min

How to Show an Account Hierarchy as a Tree Grid in Salesforce

The native account hierarchy covers accounts only, on its own page. How to show any hierarchy as a tree grid, on a page or in a flow.

Avonni Tree Grid showing a hierarchy on a Salesforce page
Video tutorial
▶
Play here

Salesforce has a native account hierarchy view, but it covers accounts only and opens on its own page. To show a hierarchy on a record page, inside a Screen Flow, on a custom object, or across several objects at once, you need a tree grid: a table whose rows expand to reveal the records below them. You can build one with code, or configure one without it. This post covers both, and what the native view already does well.

Build this Tree Grid in your org

Add the Avonni Tree Grid to record, app and home pages without code. Start free with 10 production licenses.

Install free from AppExchange

What the native account hierarchy does

On any account with a parent, the View Account Hierarchy action opens a page that shows the whole family: the parent, its children, and theirs. Admins pick up to 15 columns for it, and it displays up to 2,000 accounts. For a quick look at who owns what in a group of companies, it does the job.

Its limits show up as soon as the hierarchy becomes part of someone's daily work:

  • Accounts only. Parent cases, territories, custom objects with a self lookup: none of them get a hierarchy view.
  • Its own page. You can't drop it on the account record page next to the rest of the context, or inside a Screen Flow.
  • Read only. There are no row actions and no buttons: users look at the hierarchy, then go elsewhere to act on it.
  • One object. It can't show an account, then its opportunities, then their contacts, in the same table.

Option 1: build a tree grid with code

Salesforce's Lightning component library includes lightning-tree-grid, a base component that renders hierarchical rows. A developer writes the Lightning Web Component around it, plus the Apex that queries each level and assembles the nested data. It works, and it is yours to maintain: every new level, column or object is a code change.

Option 2: a tree grid without code

Avonni's Tree Grid does the same job without code. It exists as a Dynamic Component, for Lightning record, app and home pages, as a Flow Screen Component, for Screen Flows, and natively in Experience Builder, for portals. You configure it visually, level by level.

Avonni Tree Grid on a Salesforce page: regions expand into territories with owner, open pipeline and win rate columns
A Tree Grid built with Dynamic Components: regions expand into territories, with owner, open pipeline and win rate on every row.

Set up an account hierarchy

  1. Add the Tree Grid and choose a query as the data source, on Account. This first query returns the top of the tree: for example, the account you want to start from.
  2. Add a nested level: child object Account, relationship field Parent Account ID. Each row now expands into its child accounts.
  3. Repeat the nested level for as many generations as your hierarchy has.
  4. Pick your columns: name, owner, industry, annual revenue, anything on the account. Columns use the same display types as the Avonni Data Table, such as badges, currency and progress bars.
  5. Add row actions or header buttons if users should act from the table: open a record, launch a flow, create a child account.

Mix objects in the same tree

The levels don't have to use the same object. An account can expand into its opportunities, and each opportunity into its contact roles or products. Each level is a query on the child object, linked to its parent by a relationship field.

On a page or in a flow

  • On a record page: build the Tree Grid with Dynamic Components and drop it on the account page with Lightning App Builder.
  • In a Screen Flow: use the Tree Grid from the Avonni Flow Screen Components, for example to let users select accounts in a hierarchy before the next step. Selected rows are available as outputs.

Show the parents too: Hierarchy mode

Since the October 2026 release, the Tree Grid can also climb. Turn on Hierarchy mode, pick Parent Account ID as the lookup and pass the record Id of the page: opened from any account, the grid goes up to the top of that branch, draws the whole tree and marks the account you came from. Deeper levels load as users open them. Without Hierarchy mode, the tree still builds downward from the records its first query returns.

The three options side by side

Native account hierarchyCustom LWCAvonni Tree Grid
ObjectsAccounts onlyAnyAny, and several in one tree
WhereIts own pageAnywhere you deploy itRecord, app and home pages, Screen Flows, Experience sites
ColumnsUp to 15Your choiceYour choice, with display types
ActionsNoneYour choiceRow actions and header buttons
DirectionParents and childrenYour choiceUp to the top and down, with Hierarchy mode
CodeNoneLWC and ApexNone

FAQ

Can I show a hierarchy for a custom object?

Yes. Any object with a lookup to itself works the same way as Parent Account ID: add a nested level on the same object with that lookup as the relationship field.

How many levels can the tree have?

You add one nested level per generation. One of our customers runs a five-level account hierarchy built on Parent Account ID: group, subgroup, account, sub-account and agent code.

Can one tree mix accounts, opportunities and contacts?

Yes. Each level queries its own object, so a tree can go from accounts to opportunities to contacts.

Does it show the parents of a child account?

Yes, with Hierarchy mode, shipped in October 2026. Give the Tree Grid the Parent Account ID lookup and the current record Id: it climbs to the top of the branch and draws the tree from there.

Try it in your org

The Tree Grid is part of Avonni Dynamic Components for Lightning pages, of the Avonni Flow Screen Components for Screen Flows and of the Avonni Experience Cloud Components for portals. Install it from the AppExchange and build your first hierarchy in minutes. See the Tree Grid on every surface, filmed in real orgs. For every Screen Flow component, native and third party, see the Salesforce Flow Screen Components guide.

Filed under
Jean-Baptiste Vergé
Written by
Jean-Baptiste Vergé
Co-Founder, Head of Engineering

Co-founder of Avonni and Head of Engineering, Jean-Baptiste has spent 8+ years building the next generation of low-code development tools for Salesforce. He leads the technical vision behind Avonni's interactive prototyping and component builder platform.

Follow on LinkedIn →
Share this article
LinkedInXCopy link

Ready to build it yourself?

Start free with 10 production licenses. All 3 Avonni packages included.