Select Multiple Records in the Lookup Component

Select Multiple Records in the Lookup Component

Last Updated on February 26, 2023 by Rakesh Gupta

Big Idea or Enduring Question:

  • When using the lookup Component, allow your users to select more than one record.

This blog is a sequel to my previous blog – What? Use Lookup Field into a Flow Screen Element?!!In the previous blog, I discussed how to configure the lookup component for screen flow.

This article goes a step ahead and explains how to configure the Lookup flow screen component so that users can search and select more than one record.

Objectives:

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

  • Create a Screen Flow and add a Screen element to it.
  • Add a lookup component to your screen element
  • Set the maximum selections for the lookup element
  • Update multiple records using In operator
  • And much more

Business Use case

Edward Backhouse is working as a System Administrator at Gurukul on Cloud (GoC). He has received the following requirement from the management:

  1. Add a screen flow on the home page that allows users to select multiple opportunities
  2. In the end, update the owner for selected opportunities to the logged-In users.

Automation Champion Approach (I-do):

After the Winter’23 release, users can search and select more than one record with the Lookup flow screen component. As a flow configurator, you can specify a selection maximum and one or more default records.

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

Attribute Description
API Name An API name can include underscores and alphanumeric characters without spaces. It must begin with a letter and can’t end with an underscore. It also can’t have two consecutive underscores.
Field API Name The API name of a lookup field on the source object.
Label User-friendly text that displays to the left of the component.
Object API Name The API name of the source object.
Maximum Selections The maximum number of records that the user can select. The default value is 1.
Record Id Initially, if Maximum Selections is 1 or Maximum Selections is greater than 1 and the Record ID Collection field is null, the record ID selected by default for the lookup.

When a user runs the flow, the value changes to the flow user’s selection.

Record Id Collection Initially, if Maximum Selections is greater than 1, the default record IDs for the lookup.

If Maximum Selections is greater than 1 and the Record ID field is null, the first value is the record IDs selected by default for the lookup.

You can specify any number of record IDs up to the Maximum Selections value.

When a user runs the flow, the value changes to the flow user’s selections.

Require Requires users to enter a value before they can move 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 understand it.

Let’s begin building this automation process.

Guided Practice (We-do):

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

  1. Define flow properties for screen flow
  2. Add a Screen element
    1. Add a Lookup Component that allows users to select multiple opportunity records.
  3. Add an Update Records element to update the opportunities owner
  4. Add a screen flow to the lightning home page

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 Screen Element 

  1. On Flow Designer, click on the +icon and select the Screen element.
  2. Input the following information:
    1. Enter Label the API Name will auto-populate.
  3. Click Done

Step 2.1: Add a Lookup Component that Allow Users to Select Multiple Opportunity Records

  1. Under Input section on Screen Element. Drag and drop Lookup onto the screen. 
  2. Input the following information:
    1. Enter API Name.
    2. Field API Name: OpportunityId
    3. Label: Select Opportunities (Enter a label that appears next to the lookup control)
    4. Object API Name: Quote ( Enter the object API name) 
    5. Maximum Selection: 10
    6. Required: {!$GlobalConstant.True}
  3. Click Done.

Step 3: Add Action – Update Records

The next step is to update the selected opportunities owner. 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: Opportunity
  5. Select All Conditions Are Met (AND)
  6. Set Filter Conditions
    1. Row 1:
      1. Field: Id
      2. Operator: In
      3. Value: {!SelectOpportunities.recordIds}
    2. Click Add Condition
    3. Row 2:
      1. Field: OwnerId
      2. Operator: Does Not Equal
      3. Value: {!$User.Id}
  7. Set Field Values for the Opportunity Records
    1. Row 1:
      1. Field: OwnerId
      2. Value: {!$User.Id}
  8. Click Done.


In the end, Edward’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 LabelSelect Multiple Records – Lookup Example {!$Flow.CurrentDateTime}
  6. Click Save.

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

Step 4: Add a Screen Flow to the Lightning Home Page

The next step is to distribute a flow to Lightning Experience or Salesforce app users by embedding it on a Lightning home page.

Proof of Concept

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!

9 thoughts on “Select Multiple Records in the Lookup Component

    1. Here are my high-level solutions for your business use case:

      1️⃣ Use a Loop through {!SelectOpportunities.recordIds}
      2️⃣ Populate fields using a Record Variable.
      3️⃣ Add the Record Variable to a Collection Variable.
      4️⃣ Finally, insert the records using Record Create.

  1. Hi, great article, thanks. Question; I want to limit the number of records that a user can choose from, similar to how a lookup filter would work. But flow (1) shows me recent items (which I don’t want in my use case) and (2) the lookup filter that I applied on the source field doesn’t work in the flow. Any thoughts?

      1. My bad. Another option is to hold community user data in a temporary table/object and later create another flow on that object to insert the user. You can also use the Apex approach here if you don’t want to create an unnecessary object.

Leave a Reply

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