Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Work with selected rows

Let an account manager tick accounts in a screen flow Tree Grid, then hand those accounts and their open cases to a colleague after Next.

An account manager hands part of a customer group to a colleague. On a flow screen they open the group's hierarchy, tick the subsidiaries that change hands, and click Next. The flow then reassigns those accounts, and their open cases with them, in one pass.

Tree Grid on a flow screen with two subsidiary accounts ticked and the selection count showing 2
Two subsidiaries ticked, ready to hand over after Next.

Before you start

  • A screen flow whose first screen holds a Tree Grid showing the customer group's accounts, with the Query data source. Show an account hierarchy sets it up.

  • The examples use the API Name AccountTree. Replace it with yours in every reference.

  • With the Query source the grid keys every row on the record Id, so the key outputs below return Account Ids.

Steps

1

Keep the checkboxes on

Select the Tree Grid on the screen and click Open Component Builder. In the Properties tab:

  • Leave Hide Checkbox Column off. When it is on, users cannot tick rows and every selection output stays empty.

  • Turn on Show Number of Items Selected so the user sees how many accounts are ticked ("2 items selected", with a Clear selection link).

  • Ticking a parent row does not tick its subsidiaries: each account to hand over is ticked on its own.

The Tree Grid has no setting that makes a selection required or caps it. The third step makes it required in the flow.

2

Pick the output you need

Every element after the screen can read the selection, through five outputs:

Output variable
Reference
Use it for

Selected Rows

{!AccountTree.selectedRows}

The ticked records, for a Loop or an Update Records

Selected Rows Key Field Value

{!AccountTree.selectedRowsKeyValue}

The Ids as a text collection, for a Get Records with the In operator

Selected Rows Key Field Value comma separated

{!AccountTree.selectedRowsKeyValueCommaSeparated}

One string, 'id1','id2', the shape a SOQL IN (...) clause expects in an Apex action

Selected Rows Key Field Value semi colon separated

{!AccountTree.selectedRowsKeyValueSemiColonSeparated}

One string, id1;id2, unquoted

Selected Rows Serialized

{!AccountTree.selectedRowsSerialized}

The ticked rows as a JSON string, for an action that parses JSON

This flow uses the first two.

3

Stop when nothing is ticked

  1. After the screen, add an Assignment. Create a Number variable SelectedCount and set it with Equals Count {!AccountTree.selectedRowsKeyValue}.

  2. Add a Decision with an outcome Accounts ticked: {!SelectedCount} Greater Than 0.

  3. On the default outcome, add a screen that says "Tick at least one account", then connect it back to the Tree Grid screen.

4

Ask for the new account manager

On the Accounts ticked path, add a Screen with a standard Lookup component:

  • API Name: New_Owner

  • Object API Name: Account

  • Field API Name: OwnerId

  • Label: New account manager

The Lookup searches users, the same way the Account Owner field does.

5

Reassign the ticked accounts

  1. Add a Loop over {!AccountTree.selectedRows}, named Loop_Accounts.

  2. Inside the loop, an Assignment: {!Loop_Accounts.OwnerId} Equals {!New_Owner.recordId}, then Add {!Loop_Accounts} to a new Account record collection variable, AccountsToUpdate.

  3. After the loop (After Last Item), one Update Records on {!AccountsToUpdate}.

Updating once after the loop keeps the flow to a single database update, however many accounts were ticked.

Flow Builder canvas with the Tree Grid screen, a count check, a new owner screen, two loops and two Update Records elements
The flow after the screen: one update for the accounts, one for their open cases.
6

Move their open cases too

The cases do not sit in the grid, so fetch them from the Ids:

  1. Add a Get Records on Case, with two conditions: AccountId In {!AccountTree.selectedRowsKeyValue}, and IsClosed Equals False. Store all records.

  2. Loop over the cases the same way as in the previous step: set OwnerId to {!New_Owner.recordId}, add each case to a Case record collection, then one Update Records after the loop.

In takes the text collection as it is. The comma separated string does not work there: it is a single text value.

7

Save and test

Run the flow with Debug. Click Next with nothing ticked: the message screen appears, then the grid again. Under Meridian Group, tick two regional companies, Meridian Europe and Meridian Asia Pacific, and the grid reads 2 items selected. Click Next, pick a user in New account manager and finish. Both accounts, and every open case on them, now show that user as owner.

To act on the selection without leaving the screen, send it to a second flow from a header button instead: Add row and header actions shows how.

Troubleshooting

Selected Rows is empty after the screen

Selected Rows returns records only with the Query data source. With Manual there is no Salesforce record behind a row, so read Selected Rows Key Field Value instead. If the source is right, the user ticked nothing, or Hide Checkbox Column is on.

The Get Records returns no cases

Check that the In condition reads Selected Rows Key Field Value (the collection), not one of the separated strings, and that it filters on AccountId, not on Id.

The tree mixes accounts, contacts and cases

In a tree built across several objects, the user can tick rows of different objects. Work from the Ids: run one Get Records per object with Id In Selected Rows Key Field Value. Each one returns only the ticked records of its own object, ready for its own update. Browse accounts, contacts and cases builds that kind of tree.

Was this helpful?