> 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/pass-selected-rows-to-a-screen-flow.md).

# Pass selected Tree Grid rows to a Screen Flow

Send accounts selected across several branches of an Avonni Tree Grid to a Salesforce Screen Flow and display the chosen records for review.

An account operations team can pick accounts from separate branches and review them together. In this build, the Avonni Tree Grid sends the IDs of checked rows to a Salesforce Screen Flow. The Flow retrieves those Accounts and displays them for review without updating records.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2Fh06E1IihjgEihdtSDphN%2Fpass-selected-rows-to-a-screen-flow-result.png?alt=media" alt="The Flow dialog on an activated Lightning test page shows Alder North Field and Alder South Field in Display Text." width="640"><figcaption><p>The Flow dialog lists the two accounts selected from separate branches.</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%2Fh06E1IihjgEihdtSDphN%2Fpass-selected-rows-to-a-screen-flow-result.png?alt=media)

## Before you start

* Use the Account-only query from [Show the current account in its hierarchy](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/tree-grid/show-an-account-hierarchy.md) on a Lightning record page. Open Alder Service Group to test the two branches in this example.
* Make sure you can activate a Screen Flow and your test user can run it and read the Accounts used in the demo.
* For the generic input collection setup, see [Pass Multiple Selected Records to a Screen Flow](https://docs.avonnicomponents.com/dynamic-components/tutorials/interactions/flow-integration/how-to-pass-multiple-selected-records-from-a-dynamic-component-to-a-screen-flow.md).

## Steps

{% stepper %}
{% step %}

### Collect the selected Account IDs

1. Create a Salesforce Screen Flow named `Review Selected Accounts`, with API name `Review_Selected_Accounts`. Create a **Text** variable named `selectedAccountIds` and select **Allow multiple values (collection)** and **Available for input**.
2. Create a **Number** variable named `selectedCount` with zero decimal places. In an **Assignment**, set `selectedCount` to the count of `selectedAccountIds` using **Equals Count**.
3. Add a **Decision**. Route `selectedCount` greater than `0` to the Account lookup in the next step. For the default outcome, add a screen with **Display Text** that says `Select one or more accounts to review.`
   {% endstep %}

{% step %}

### Display the selected account names

1. Use **Get Records** to retrieve all Account records whose `Id` is **In** `selectedAccountIds`. Sort by `Name` in ascending order. Store `Id` and `Name` in an Account record collection variable named `selectedAccounts`.
2. Add a **Loop** with API name `For_Each_Account` over `selectedAccounts`. Create a **Text** variable named `accountNames` and a **Text** formula named `nextAccountNames` with this expression.

   ```
   IF(ISBLANK({!accountNames}), {!For_Each_Account.Name}, {!accountNames} & ", " & {!For_Each_Account.Name})
   ```
3. For each loop item, use an **Assignment** to set `accountNames` to `nextAccountNames` and return to the loop.
4. Create a **Text** formula named `reviewSummary` for the final result.

   ```
   IF(ISBLANK({!accountNames}), "No selected accounts are available to review.", {!accountNames})
   ```
5. After the last loop item, open a screen with a **Display Text** component and insert `reviewSummary`. Save and activate the Flow.
   {% endstep %}

{% step %}

### Add a Tree Grid header action

1. Select the Tree Grid in Component Builder. Under **Properties** > **Content**, turn **Hide Checkbox Column** off if you enabled it for the hierarchy tutorial. Turn on **Show Number of Items Selected**.
2. Under **Header**, add an item in **Actions**. Set **Label** to `Review selected accounts` and **Name** to `reviewSelectedAccounts`.
3. In **Interactions**, add an action under **Header Action Click**. Set **Target Name** to **Review selected accounts** and select **Open Flow Dialog**. For **API Name**, select the activated `Review_Selected_Accounts` Flow.
   {% endstep %}

{% step %}

### Map the selected IDs as a collection

In **Input Variables**, add a mapping.

1. For **Name**, select `selectedAccountIds`.
2. For **Value**, open the resource selector. Under **Components**, open your Tree Grid and select **Selected Rows Key Value**.
3. Set **Type** to **Text** and enable **Allow Multiple Values (collection)**. The grid uses Salesforce record IDs as row keys in Query mode. The Flow receives those IDs as individual values.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FvBh5KAXF2oRcW6IxjIhi%2Fpass-selected-rows-to-a-screen-flow-mapping.png?alt=media" alt="Flow dialog input mapping for the Tree Grid selected row keys as a text collection" width="320"><figcaption><p>Map the Tree Grid's selected IDs to the Flow input collection.</p></figcaption></figure>
{% endstep %}

{% step %}

### Save and test changes to the selection

1. Save and activate the component version used on the Lightning page. Open the Alder Service Group Account. Expand Alder North and Alder South.
2. With all checkboxes clear, choose **Review selected accounts** and confirm the empty-selection message appears. Close the dialog.
3. Check Alder North Field and Alder South Field. Confirm that the grid shows two selected rows. Choose **Review selected accounts**. Compare the two Account names on the Flow screen with the records you checked.
4. Close the dialog, uncheck Alder North Field, and open the dialog again. Confirm the Flow displays only Alder South Field.
5. Close the dialog, clear the remaining checkbox, and open it again. Confirm the empty-selection message appears.
   {% endstep %}
   {% endstepper %}

## Troubleshooting

<details>

<summary>The dialog opens without the selected accounts</summary>

Confirm the input is a Text collection on both sides. Choose **Selected Rows Key Value** in Component Builder. A string containing several IDs does not match this Flow's input type. Check that the Flow filters Account records by `Id` and that the test user can read those records.

</details>

<details>

<summary>The Flow does not appear in the picker</summary>

Confirm the Flow is active and that the user who opens the dialog has access to run it.

</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) to configure the Account branches used here.
* [Pass Multiple Selected Records to a Screen Flow](https://docs.avonnicomponents.com/dynamic-components/tutorials/interactions/flow-integration/how-to-pass-multiple-selected-records-from-a-dynamic-component-to-a-screen-flow.md) for general input collection setup.
* [Tree Grid reference](https://docs.avonnicomponents.com/dynamic-components/components/tree-grid.md) for row selection and header actions.


---

# 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/pass-selected-rows-to-a-screen-flow.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.
