Display Records Data in a Table Using DataTable

Display Records Data in a Table Using DataTable

Last Updated on October 9, 2022 by Rakesh Gupta

Big Idea or Enduring Question:

  • How to display records in a table using the datatable and process selected records? 

Objectives:

After reading this blog, you’ll be able to:

  • Understand how to use data table
  • Works with Get Records element to fetch records
  • Add columns to datatable
  • Update multiple records using In operator
  • And much more

Business Use case

Rachel Gillett is working as a Junior Developer at Gurukul on Cloud (GoC). She has received the following requirement from the management:

  1. Add a button on the account object that opens up a screen that allows sales reps to select multiple related open opportunities.
  2. Provide an option to select Stage for the selected opportunities.
  3. In the end, update the stage for selected opportunities.

Automation Champion Approach (I-do):

Salesforce Screen Flow DataTable is a powerful and smart table component provided by Salesforce Flow. It is a highly flexible component that displays information in tables and adds interactions to them. 

There are a few possible solutions for the above business scenario. We will use Screen Flow and Data Table (Beta) to solve the requirement.

Before we proceed further, let us understand the characteristics of the DataTable component. 

Attribute Details
Source Collection Collection of records to use to populate the table.
Row Selection Mode Indicates how many rows the user can select in the table. You can set the value to:

Multiple
The user can select any number of rows between the Minimum Row Selection and Maximum Row Selection values.
Single
The user can select up to one row.
View only
The user can’t select any rows.
Minimum Row Selection Specifies the minimum number of rows that the user must select.
Maximum Row Selection Specifies the maximum number of rows that the user can select.
Default Selection The collection specifies which records to preselect in the table.
Require user to make a selection Specifies the maximum number of rows that the user can select. Specifies whether the user must select a row before navigating to the next screen.

Before discussing the solution, let me show you a diagram of a Process Flow at a high level. Please spend a few minutes going through the following Flow diagram and understanding it.

Let’s begin building this automation process.

Guided Practice (We-do):

There are 9 steps to solve Rachel’s business requirement using Screen Flow. We must:

  1. Define flow properties for screen flow
  2. Add a text variable to store the account Id
  3. Add a text collection variable to store the selected opportunity Ids
  4. Add a Get Records element to find the open opportunities 
  5. Add a Screen element to display the records in a table format and a Stage drop-down
  6. Add a loop element to extract selected opportunities from the record collection variable (step 5)
  7. Add an assignment element to add opportunity Id to the collection variable (Created in step 1.3)
  8. Add an Update Records element to update the opportunity stage of selected records 
  9. Create a Quick Action to Launch the Flow.

Step 1: Define Flow Properties

  1. Click Setup.
  2. In the Quick Find box, type Flows.
  3. Select Flows, then click on the New Flow.
  4. Select the Screen Flow option and click on Create and configure the flow. 
  5. It will open the flow designer for you.

Step 2: Add a Text Variable to Store Account Id

  1. Under Toolbox, select Manager, then click New Resource to store the account Id. 
  2. Input the following information: 
    1. ResourceType: Variable
    2. API Name: recordId
    3. Data Type: Text
    4. Default Value: {!$GlobalConstant.EmptyString}
    5. Check Available for Input
    6. Check Available for Output
  3. Click Done.

Step 3: Add a Collection Variable Text to Store Selected Opportunity Ids

  1. Under Toolbox, select Manager, then click New Resource to store the selected Opportunity Ids.
  2. Input the following information: 
    1. ResourceType: Variable
    2. API Name: varT_OpportunityIds
    3. Data Type: Text
    4. Default Value: {!$GlobalConstant.EmptyString}
    5. Check Allow multiple values (collection) 
    6. Check Available for Input
    7. Check Available for Output
  3. Click Done.

Step 4: Adding a Get Record Element to Find the Open Opportunities  

The next step is using the Opportunity object to find the open opportunities on the current account. 

  1. On Flow Designer, click on the +icon and select the Get Records element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Select the Opportunity object from the dropdown list.
  4. Select All Conditions Are Met (AND)
  5. Set Filter Conditions
    1. Row 1:
      1. Field: AccountId
      2. Operator: Equals
      3. Value: {!recordId}
    2. Click Add Condition
    3. Row 2:
      1. Field: IsClosed
      2. Operator: Equals
      3. Value: {!$GlobalConstant.False}
  6. How Many Records to Store:
    1. Select All record
  7. How to Store Record Data:
    1. Choose the option to Automatically store all fields
  8. Click Done.

Step 5: Add a Screen Element to Display the Open Opportunities in a Table Format and a Stage Drop-down

  1. Under Get Opportunities Node, click on the +icon and select the Screen element on Flow Designer.
  2. Input the following information:
    1. Enter Label the API Name will auto-populate.
  3. Check out the video for step-by-step instructions and some tips.

Step 6: Add a Loop Element to Extract Selected Opportunity Records from Record Collection Variable (Step 5) 

  1. On Flow Designer, click on the +icon and select the Loop element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. For Collection Variable select {!Open_Opps.selectedRows}.
  4. For Specify Direction for Iterating Over Collection, select the option First item to last item.
  5. Click Done.

Step 7: Adding an Assignment Element to Add Opportunity Id to the Collection Variable Text (Created in step 1.3)

  1. On Flow Designer, click on the +icon and select the Assignment element. 
  2. Enter a name in the Label the API Name will auto-populate.
  3. Set Variable Values
    1. Row 1:
      1. Field: {!varT_OpportunityIds}
      2. Operator: Add
      3. Value: {!Loop_through_Selected_Record.Id}
  4. Click Done.

Step 8: Adding an Update Records Element to Update the Opportunity Stage of Selected Records

The next step is to update the opportunity stage of selected records. We will use the Update Records element. 

  1. On Flow Designer, click on the +icon and select the Update Records element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. For How to Find Records to Update and Set Their Values select Specify conditions to identify records, and set fields individually
  4. Object: Account
  5. Select All Conditions Are Met (AND)
  6. Set Filter Conditions
    1. Row 1:
      1. Field: Id
      2. Operator: In
      3. Value: {!varT_OpportunityIds}
  7. Set Field Values for the Opportunity Records
    1. Row 1:
      1. Field: StageName
      2. Value: {!Stage}
  8. Click Done.

In the end, Rachel’s Flow will look like the following screenshot:

Once everything looks good, perform the steps below:

  1. Click Save.
  2. Enter the Flow Label the API Name will auto-populate.
  3. Click Show Advanced.
  4. API Version for Running the Flow: 56
  5. Interview Label: DataTable Flow Example {!$Flow.CurrentDateTime}
  6. Click Save.

Almost there! Once everything looks good, click the Activate button.

Step 9: Create a Quick Action to Launch the Flow

The next step is to create a Quick Action on the Account object to launch the Screen Flow. Salesforce will automatically pass the Account Id to the recordId variable.

  1. Click Setup.
  2. In the Object Manager, type Account.
  3. Select Buttons, Links, and Action, then click New Action.
  4. Input the following information:
    1. Select Flow as Action Type.
    2. Select DataTable Flow Example as Flow.
    3. Enter Label (Update Opportunity) the Name will auto-populate.
  5. Click Save.

Make sure to add the Quick action to the Account Lightning Record Pages. 

👉 Check out the video for step-by-step instructions. 

Proof of Concept

From now onwards, whenever a user clicks on the Update Opportunity button, Flow will populate a screen with open opportunities. 

Formative Assessment:

I want to hear from you!

What is one thing you learned from this post? How do you envision applying this new knowledge in the real world? Feel free to share in the comments below.

Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.