> 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/dynamic-components/tutorials/components/tree-grid/show-an-account-hierarchy.md).

# Show the current account in its hierarchy

Show where an Account sits in its corporate structure by displaying its parent and child accounts in a Tree Grid on the Salesforce record page.

Before a service review, an account manager opens Alder North and needs to see which group owns it and which branch reports to it. Add an Avonni Tree Grid to the Account page and use the page's record ID to locate the account in the hierarchy.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FvJOW8wiae2rMb0bMsxvC%2Fshow-an-account-hierarchy-result.png?alt=media" alt="An activated Lightning Account test page with Alder Service Group above the current Alder North row and Alder North Field below it."><figcaption><p>On the Lightning test page, the Tree Grid marks Alder North as the current account.</p></figcaption></figure>

## Before you start

* Use a sandbox with Avonni Dynamic Components and access to build a component and assign a test Lightning Account record page. Verify that your test user can read the accounts and the parent lookup.
* Create an Account called `Alder Service Group`. Create `Alder North` and `Alder South` with that Account as their parent. Set the parent of `Alder North Field` to `Alder North` and the parent of `Alder South Field` to `Alder South`.
* Create a separate Account called `Birch Service Group` with no parent. Use it to check that the grid follows the record page.

## Steps

{% stepper %}
{% step %}

### Create an Account component

1. Open **Dynamic Components**, click **New Component**, and select **Create Blank Component**.
2. Drag **Tree Grid** from the component library onto the canvas and save.
3. Set **Target Page Object** to **Account**. In the Tree Grid's **Properties** tab, set **Title** to `Account hierarchy`.
   {% endstep %}

{% step %}

### Choose the Account parent lookup

1. In **Properties**, set **Data Source** to **Query** and create a **Query Resource**.
2. Set **Mode** to **Hierarchy** and **Object API Name** to `Account`.
3. In **Parent Lookup Field**, select **Parent Account ID** (`ParentId`) and save the query.

The Tree Grid uses that lookup to find the current Account's branch. The Account records provide the relationships.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FMf7t0kfedp7gLAomYNJo%2Fshow-an-account-hierarchy-query.png?alt=media" alt="Tree Grid query set to Hierarchy mode with Account and its parent lookup selected" width="640"><figcaption><p>Hierarchy uses the Account parent lookup to connect levels.</p></figcaption></figure>
{% endstep %}

{% step %}

### Bind the current account and show its name

1. Under **Hierarchy**, choose **RecordId** for **Current Record ID**.
2. Under **Data Mappings**, add an **Object Field** column. Set **Object API Name** to `Account` and **Source Field** to the account name (`Name`).
3. Under **Content**, turn on **Hide Checkbox Column**. This view is for browsing the hierarchy.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FImmFP1qlbK9BmlBgIoPb%2Fshow-an-account-hierarchy-current-record.png?alt=media" alt="Tree Grid Hierarchy settings with Current Record ID bound to the page record" width="640"><figcaption><p>Current Record ID identifies the Account that the reader opened.</p></figcaption></figure>
{% endstep %}

{% step %}

### Save and test

1. Save and activate the Dynamic Component. Add it to a test Lightning Account record page using [Publishing your Dynamic Components](https://docs.avonnicomponents.com/dynamic-components/core-concepts/publishing-your-dynamic-components.md).
2. Open **Alder North**. Check that **Alder Service Group** appears above it, and that the current badge is beside **Alder North**. Expand **Alder North** if needed and check for **Alder North Field** below it.
3. Open **Alder South**. Check that its row now has the current badge and that its child is **Alder South Field**.
4. Open **Birch Service Group**. Check that it is the current row and that the Alder records are absent.

Compare the grid with the parent lookup values on the original Account records.
{% endstep %}
{% endstepper %}

## Troubleshooting

<details>

<summary>The grid is empty on the record page</summary>

Check that **Current Record ID** uses the page's record ID and that this component is placed on an Account record page. Open the page as your test user and check that the user can read the Account records.

</details>

<details>

<summary>The Account appears but its expected parent is missing</summary>

Open the Salesforce Account and check which record its parent lookup points to. In the query, confirm that **Mode** is **Hierarchy** and that **Parent Lookup Field** uses `ParentId`.

</details>

## Related tutorials

* [Browse accounts, contacts and cases](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/tree-grid/browse-accounts-contacts-and-cases.md) uses child queries to browse records from several Salesforce objects.
* [Tree Grid reference](https://docs.avonnicomponents.com/dynamic-components/components/tree-grid.md) explains the query modes, column settings, and count options.


---

# 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/dynamic-components/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.
