> 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/browse-accounts-contacts-and-cases.md).

# Browse accounts, contacts and cases

Browse open support cases by contact and account in one Salesforce Tree Grid, so service teams can review each branch without opening separate related lists.

Before a customer review, a service lead wants to find each field office's contacts and see which of those contacts have open cases. Use an Avonni Tree Grid with a Multi-Level query. The Account rows open onto their Contacts, and the Contact rows open onto their open Cases.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2Fv7cIjn7HIyzfkLnB5DIY%2Fbrowse-accounts-contacts-and-cases-result.png?alt=media" alt="An activated Lightning test page showing the open Pump inspection and Sensor replacement cases nested under their contacts in two field office branches."><figcaption><p>The Lightning test page shows each open case under its contact and field office.</p></figcaption></figure>

[Open the full-size image](https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2Fv7cIjn7HIyzfkLnB5DIY%2Fbrowse-accounts-contacts-and-cases-result.png?alt=media)

## Before you start

* Use a sandbox with Avonni Dynamic Components and access to build a component and assign a test Lightning record page. Give your test user read access to the test records and mapped fields.
* Create two Accounts called `Alder North Field` and `Alder South Field`. Add Maya Chen and Eli Brooks to the North Account and Noor Patel to the South Account.
* On Maya's Contact, create an open Case with the subject `Pump inspection` and a closed Case with the subject `Calibration follow-up`. On Noor's Contact, create an open Case with the subject `Sensor replacement`. On each Case, set the Account and Contact to match the relationship above. Leave Eli without a Case.

## Steps

{% stepper %}
{% step %}

### Add the grid and choose the top-level accounts

1. In **Dynamic Components**, create a blank component and add **Tree Grid**. In **Properties**, set **Title** to `Field office support cases`.
2. Set **Data Source** to **Query** and create a **Query Resource**. In **Mode**, choose **Multi-Level**.
3. In **Nested Queries**, click **Add Item** and add an `Account` root query. Under **Filters**, add two conditions on the account name (`Name`), one **Equals** `Alder North Field` and the other **Equals** `Alder South Field`.
4. Choose **Any Condition Is Met**, so either account can match. Confirm the query entry with **Done**.
   {% endstep %}

{% step %}

### Nest contacts and open cases

1. Use the Account query entry's **Add** action to add a child query. In **Child Object API Name**, choose `Contact`. In **Relationship Field**, choose **Account ID** (`AccountId`). Click **Done**.
2. Use the Contact query entry's **Add** action to nest one more query. Choose `Case` as **Child Object API Name** and **Contact ID** (`ContactId`) as **Relationship Field**.
3. Under the Case query's **Filters**, set **Closed** (`IsClosed`) **Equals** false. Click **Done** and save the query resource.

The Case lookup points to Contact, which is the level directly above it. Cases without a matching Contact stay out of the tree.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FWftXzqFC8NXHX9M7FgDJ%2Fbrowse-accounts-contacts-and-cases-child-query.png?alt=media" alt="Case child query using the Case contact lookup as its relationship to Contact" width="640"><figcaption><p>The Case query uses the contact lookup to place cases beneath their contacts.</p></figcaption></figure>
{% endstep %}

{% step %}

### Map the columns for each level

In **Data Mappings**, add the columns in this order. For each, select **Object Field** and set **Object API Name** and **Source Field**.

| Object API Name | Source Field          | Column header |
| --------------- | --------------------- | ------------- |
| Account         | Account name (`Name`) | Record        |
| Case            | Subject (`Subject`)   | Subject       |
| Case            | Status (`Status`)     | Status        |

On the first column, turn on **Custom Label** and set **Label** to `Record`. That column shows each level's record name, including the case number for Cases. The Subject and Status columns apply to Case rows.
{% endstep %}

{% step %}

### Save and test

1. Save and activate the Dynamic Component. Add it to your test Lightning page using [Publishing your Dynamic Components](https://docs.avonnicomponents.com/dynamic-components/core-concepts/publishing-your-dynamic-components.md).
2. Check that the grid starts with the two field offices. Expand **Alder North Field**. It should contain **Maya Chen** and **Eli Brooks**.
3. Under **Maya Chen**, look for **Pump inspection**. Confirm that **Calibration follow-up** is absent. **Eli Brooks** should have no Case rows.
4. Expand **Alder South Field** and **Noor Patel**. Check that **Sensor replacement** appears under Noor and that Maya's Case does not.

Compare these results with the Account and Contact lookups on the source records and the closed state on each Case.
{% endstep %}
{% endstepper %}

## Troubleshooting

<details>

<summary>A case is missing or appears under the wrong contact</summary>

Check the Case's contact lookup and closed state. Under the Contact query, confirm the Case query's **Relationship Field** is `ContactId`.

</details>

<details>

<summary>A contact appears without case details</summary>

Case fields are filled on the Case rows. Expand the Contact if it has a matching open Case. If the Case row appears with no subject or status, check that those columns use `Case` as **Object API Name** and that your test user can read the fields.

</details>

## Related tutorials

* [Show the current account in its hierarchy](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/tree-grid/show-an-account-hierarchy.md) uses a self-referencing Account lookup when all levels come from one object.
* [Open a record from a nested row](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/tree-grid/open-a-nested-record.md) adds a row action for following the grid back to a Salesforce record.
* [Tree Grid reference](https://docs.avonnicomponents.com/dynamic-components/components/tree-grid.md) lists the column mappings and other configuration 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/browse-accounts-contacts-and-cases.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.
