> For the complete documentation index, see [llms.txt](https://docs.avonnicomponents.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.avonnicomponents.com/flow/tutorials/components/tree-grid/show-an-account-hierarchy.md).

# Show an account hierarchy

Show the whole customer group around the account the user is on, parent and subsidiaries, in a screen flow Tree Grid built from one query.

An account manager opens Meridian Chicago Hub and wants to know where it sits in the customer group: which company it reports to, which sister hubs exist, how much revenue each one brings. With the [Tree Grid](https://docs.avonnicomponents.com/flow/flow-components/tree-grid.md) in **Hierarchy** mode, a screen flow on the Account page shows the whole group from the top, with the branch down to Meridian Chicago Hub already open and its row marked.

<figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2FauSRYPOgkOabasb3TwLk%2Fflow-tutorial-tree-grid-show-an-account-hierarchy-result.png?alt=media" alt="A Tree Grid in a screen flow showing the Meridian Group account hierarchy opened down to Meridian Chicago Hub, which is marked as the current record, with a count in brackets beside each parent row and type, city, employees and annual revenue columns"><figcaption><p>Opened from Meridian Chicago Hub: the whole group, with the branch down to it already open and a count beside each parent.</p></figcaption></figure>

## Before you start

* Your accounts use the standard **Parent Account** field, so each subsidiary points at its parent.
* Your screen flow has a `recordId` input variable (Text, available for input) and runs on the Account record page with **Pass record ID into this variable** checked. If not, follow [How to pass your current RecordID in your screen flow](https://docs.avonnicomponents.com/flow/tutorials/tips-and-tricks/how-to-pass-your-current-recordid-in-your-screen-flow.md).
* Avonni Flow Components is installed in your org.

## Steps

{% stepper %}
{% step %}

### Add the Tree Grid to a screen

1. In Flow Builder, add a Screen element and drag the Avonni **Tree Grid** onto it.
2. Select it and click **Open Component Builder**.
3. In the **Header** group of the **Properties** tab, set **Title** to `Customer group`.
4. Turn on **Show Number of Children**, in the same tab, so each parent row shows how many companies sit below it.
   {% endstep %}

{% step %}

### Query the Account object

1. Open the **Data Source** section of the **Properties** tab, just above **Data Mappings**, and choose **Query**.
2. Set **Object API Name** to `Account`.
3. Under **Order By**, add **Account Name**, ascending, so sister companies read in alphabetical order.

Leave **Filters** empty for now. In this mode they apply at every level of the hierarchy, so a filter on the top account also hides subsidiaries that do not match it.
{% endstep %}

{% step %}

### Switch the query to Hierarchy mode

1. In the query editor, set **Mode** to **Hierarchy**.
2. Set **Parent Lookup Field** to **Parent Account ID**.

There is no level to add: with the lookup chosen, the grid reads parents and children from the same object, as deep as the hierarchy goes. The list only offers lookups from Account to Account.

<figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2FlAx5grBoYMo9n4EaUsuA%2Ftree-grid-hierarchy-mode.png?alt=media" alt="The Tree Grid query editor in Flow Builder with Mode set to Hierarchy and the Parent Lookup Field set to Parent Account ID" width="320"><figcaption><p>Hierarchy mode on Account. One lookup to itself replaces the levels.</p></figcaption></figure>
{% endstep %}

{% step %}

### Give the grid the account the user is on

1. In the **Properties** tab, open the **Hierarchy** group. It sits between **No Results Message** and **Data Source**.
2. Map **Current Record ID** to your flow's `recordId` variable (the picker shows it as **Record Id**).

The grid climbs from that account to the top of its group, then opens the branch back down to it. Without a value it shows no rows at all.

<figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2FKVtnUfXx79ZYnkxKhWg5%2Ftree-grid-show-an-account-hierarchy-current-record.png?alt=media" alt="The Hierarchy group of the Tree Grid Properties tab in Flow Builder, with Current Record ID mapped to the recordId flow variable" width="320"><figcaption><p>Current Record ID takes the flow's recordId.</p></figcaption></figure>
{% endstep %}

{% step %}

### Choose the columns

Under **Data Mappings**, add one entry per column, all on `Account`:

| Source Field   | Type     | Why                                                |
| -------------- | -------- | -------------------------------------------------- |
| Account Name   | Text     | First column: it carries the toggles and the tree. |
| Account Type   | Text     | Direct customer or channel.                        |
| Billing City   | Text     | Where each company sits.                           |
| Employees      | Number   | Size at a glance.                                  |
| Annual Revenue | Currency | Compare the companies of the group.                |

For the two number columns, open **Cell Attributes** and set **Alignment** to right, so the figures line up.
{% endstep %}

{% step %}

### Save and test

1. Save and activate the flow.
2. Open Meridian Chicago Hub (or any account with a parent) and run the flow from its page.

You see Meridian Group as the only top row. Its branch is open down to Meridian North America, then Meridian US Logistics, then Meridian Chicago Hub, which carries a grey **current** badge. Meridian Atlanta Hub and Meridian Dallas Hub sit beside it. Meridian Europe stays closed until the user opens it; Meridian Asia Pacific has no subsidiaries, so it has no toggle.

With **Show Number of Children** on, each parent row carries a count in brackets: Meridian Group reads (10), and the three branches below it read Meridian Europe (2), Meridian North America (5) and Meridian US Logistics (3). In **Hierarchy** mode that count covers the row's whole subtree, not only the companies directly under it.

To test from Flow Builder instead, see [Test a screen flow that needs a record Id](https://docs.avonnicomponents.com/flow/tutorials/tips-and-tricks/test-a-screen-flow-that-needs-a-record-id.md).
{% endstep %}
{% endstepper %}

{% hint style="info" %}
To show a group's contacts and cases as well, you need several objects, which **Hierarchy** mode does not read. Use **Multi-Level** instead: [Browse accounts, contacts and cases](https://docs.avonnicomponents.com/flow/tutorials/components/tree-grid/browse-accounts-contacts-and-cases.md).
{% endhint %}

## Troubleshooting

<details>

<summary>The grid is empty on the record page, with no error</summary>

**Current Record ID** has no value at runtime. The flow is not receiving `recordId`: check **Pass record ID into this variable** on the Flow component in Lightning App Builder, and the variable name (`recordId`, exactly). In the Component Builder preview the same situation shows "Hierarchy mode requires both a parent lookup field and record ID."

</details>

<details>

<summary>"Hierarchy mode requires both a parent lookup field and record ID."</summary>

The preview has no **Parent Lookup Field** or no **Current Record ID** to start from. Pick **Parent Account ID** in the query editor, and give the preview a record. Or set **Mode** back to **Multi-Level** if you did not mean to use a hierarchy.

</details>

<details>

<summary>Only one account shows, with no toggle</summary>

The account has no parent and no subsidiary, so its group is itself. Try an account whose **Parent Account** is filled.

</details>

<details>

<summary>Some subsidiaries are missing</summary>

A condition under **Filters** applies to every level. An account that does not match it is left out, even deep in the tree. Remove the filter or widen it.

</details>

<details>

<summary>I tried a filter on Parent Account ID instead</summary>

A filter such as **Parent Account ID** Equals `{!recordId}` returns one level: the direct subsidiaries, with no parent above them and nothing below. **Current Record ID** in **Hierarchy** mode is the setting that builds the whole tree.

</details>

## Related tutorials

* [Browse accounts, contacts and cases](https://docs.avonnicomponents.com/flow/tutorials/components/tree-grid/browse-accounts-contacts-and-cases.md): open each company onto its contacts and their open cases.
* [Work with selected rows](https://docs.avonnicomponents.com/flow/tutorials/components/tree-grid/work-with-selected-rows.md): let the user tick accounts of the group and update them after the screen.
* [Add row and header actions](https://docs.avonnicomponents.com/flow/tutorials/components/tree-grid/add-row-and-header-actions.md): open an account of the group from its row.
* [Filter a Data Table or Map by the current record](https://docs.avonnicomponents.com/flow/tutorials/tips-and-tricks/filter-a-data-table-or-map-by-the-current-record.md): the same `recordId`, used in a query filter.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.avonnicomponents.com/flow/tutorials/components/tree-grid/show-an-account-hierarchy.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
