Ora

How do I create a table in screen flow in Salesforce?

Published in Salesforce Flow Table 5 mins read

Creating a table in a Salesforce Screen Flow is a powerful way to display collections of records, allowing users to view, search, and even select specific items for further processing within the flow. This is achieved using the standard Data Table component.

Understanding the Data Table Component

The Data Table component is a pre-built element available in Salesforce Flow Builder designed specifically for displaying lists of records (sObject collections) on a screen. It simplifies the process of presenting data in an organized, tabular format without requiring custom code.

Steps to Create a Data Table in Screen Flow

To effectively implement a Data Table in your Screen Flow, follow these structured steps:

1. Prepare Your Data

Before you can display records in a table, you need to retrieve them. This typically involves a "Get Records" element or a loop that populates an sObject collection variable.

  • Create a Collection Variable: In Flow Builder, navigate to Manager > New Resource.
    • Resource Type: Variable
    • API Name: e.g., accountsToDisplay
    • Data Type: Record
    • Allow Multiple Values (Collection): Check this box.
    • Object: Select the object whose records you want to display (e.g., Account, Contact, Opportunity).
  • Use a Get Records Element:
    • Add a Get Records element to your flow before the screen where your Data Table will appear.
    • Label: e.g., Get Accounts
    • Object: Select the same object as your collection variable.
    • Filter Records: Define criteria to select which records to retrieve (e.g., Active = True). If you want to display search results, you might set this dynamically based on user input from a previous screen (e.g., Name Contains {!searchText}).
    • How to Store Record Data: Select "All records" and choose to "Automatically store all fields" or "Choose fields and assign variables (advanced)" into your previously created sObject collection variable.

2. Add the Data Table Component to Your Screen

Once you have your data collection ready, you can add the table to a screen.

  • Add a Screen Element: Drag a Screen element onto your canvas.
  • Label: Provide a meaningful label for your screen.
  • Drag Data Table: From the Components pane on the left, drag the Data Table component onto your screen canvas.

3. Configure the Data Table Properties

With the Data Table on your screen, you'll need to configure its basic properties.

  • API Name: Give it a unique API name (e.g., accountDataTable).
  • Label: This is the user-facing title for your table (e.g., "Select an Account").
  • Source Collection: Crucially, select the sObject collection variable you prepared in Step 1 (e.g., {!accountsToDisplay}). This tells the table which records to display.
  • Row Selection Mode: Determine how users can interact with rows:
    • View Only: Users can see the data but cannot select rows.
    • Single: Users can select only one row.
    • Multiple: Users can select multiple rows.
  • Minimum Number of Rows Selected (Optional): If row selection is enabled, you can set a minimum requirement.
  • Maximum Number of Rows Selected (Optional): If row selection is enabled, you can set a maximum limit.

4. Define Columns

Now, specify which fields from your source collection should be displayed as columns in the table.

  • Configure Columns Section: In the Data Table properties, scroll down to the "Configure Columns" section.
  • Add Columns: Click "Add Column" for each field you want to display.
  • Column Details:
    • Field API Name: Enter the API name of the field from your sObject (e.g., Name, Industry, AnnualRevenue).
    • Label: The header text for the column (e.g., "Account Name").
    • Type: Salesforce usually infers this, but you can override it (e.g., Text, Number, Currency).
    • Width (Optional): Set a fixed width or leave it as "Auto" for responsive sizing.
    • Sortable (Optional): Allow users to sort the table by this column.

5. Handle User Selections (Optional)

If you've enabled Single or Multiple row selection, you'll likely want to use the selected records later in your flow.

  • Create a Record Variable or Collection Variable for Selections:
    • If Single selection: Create a Record variable (not a collection) of the same object type.
    • If Multiple selection: Create a Record Collection variable of the same object type.
  • Access Selections: After the screen, you can access the selected records using the Data Table's output variables:
    • {!accountDataTable.firstSelectedRow} (for Single selection)
    • {!accountDataTable.selectedRows} (for Multiple selection)
  • Use in Subsequent Elements: You can then use these variables in other flow elements (e.g., to update records, create tasks, or navigate to a record page).

6. Test Your Flow

Always save and debug your flow to ensure the Data Table displays correctly and that any selection logic works as expected.

Practical Use Cases and Tips

  • Displaying Search Results: Create a text input field on a screen for users to enter search terms (e.g., part of an account name). Use a Get Records element with a Contains operator to filter records based on this input. The resulting collection can then be displayed in your Data Table. For instance, a flow can allow users to search for an account name, even just part of it, using a "contains" formula to match records.
  • Record Selection for Updates: Allow users to select one or more records from a table to perform a bulk update or a specific action on those chosen records.
  • Review and Confirmation: Present a summary of records that will be processed or created, giving users a chance to review before finalizing.
  • Pagination and Sorting: The Data Table component inherently provides pagination and sorting capabilities if configured, which is crucial for displaying large datasets efficiently.

By following these steps, you can effectively create and utilize a Data Table within your Salesforce Screen Flows, enhancing user experience and streamlining data interaction.