By: Shashank Parashar

Lookup Screen Component in Salesforce Lightning Flow: Salesforce released a new screen component – Lookup. As the name suggests, this new screen component allows users to search for a record in a flow similar to a lookup field in Salesforce.

Prior to this function, the only option to select a record in the flow was to use the picklist screen component and have each picklist value denote a separate record of an object. 

Users can easily search and define the record in the flow when using the lookup screen component. Users can also set the current recordID or default value in the lookup field in the flow so that users don’t have to select the record every time they are running the flow from a record.

How to Use the Lookup Screen Component in Salesforce Lightning Flow?

Let’s consider a use case where you need to create a screen flow and want to have input from the users. Once the flow is executed, you want to create a record from the user’s input and relate it back to a parent object.

In my case, I have a survey object that has a lookup relationship with the account. On the account page, I want the users to go through a set of screens, and then the flow will create a Survey record. Once the flow is executed, it will show up as a related list on the account page.  From here, we need to link the survey record to the account record by mentioning a value on the lookup field in the flow.

In the above screenshot, I added a lookup field by the name of Account in order to display the account records in my lookup field.

Field API name – Enter the API name of the field (a lookup field to the object of which you want to show the records). In my survey object, I have a field by the API name AccountName__c which is a lookup to accounts.

Label – Field label of the lookup field which appears on the flow screen.

Object API name – The API name of the source object. The object where the field API name is present.

Record ID– Record ID value for the lookup. You can mention the current Record ID so that by default the lookup field shows the current record from which the flow is executed.

Require – Requires users to enter a value before they can move to the next screen.

Configure 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 cannot 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.

Record ID

Record ID value for the lookup.

Require

Requires users to enter a value before they can move to the next screen.

Store the Lookup Component’s Values in the Flow

When you add a screen component to a flow, we automatically store all the attribute values in a variable.

When the user navigates to the next screen, the values are assigned to the flow variable.

To store values manually, select Manually assign variables (advanced).

All attributes are available to store in flow variables, but you likely have to store these attributes.

ATTRIBUTE

DESCRIPTION

Record ID


The ID of the record that the user selects.

You can store this value in a Text variable.

Record Name


The name of the record that the user selects.

You can store this value in a Text variable.

Note: By default, screen components that require Lightning runtime have no memory. If a user enters a value, navigates to another screen, and returns to the component’s screen, the user-entered value is lost. To enable a flow to remember the value of an attribute, set the attribute. The flow stores the value automatically. If you store values manually, store the attribute’s output value in a variable.

Considerations

  • Dependent lookup filters aren’t enforced for the Lookup component in a flow. Other lookup filters are enforced the same as they are in Lightning Experience record pages. When the flow accesses the Salesforce database, lookup filters are enforced. For example, when the flow executes the Create Records element, the flow fails if the value of the lookup field doesn’t meet the lookup filter requirements.
  • The running user of a flow must have the Create permission on the source object. For example, to search a contact’s account, the running user must have the Create permission on the Contact object.
  • A custom lookup field to a user record isn’t supported.

Note: To let a flow user choose from a list of user records, employ a standard User lookup field like CreatedById or LastModifiedById. Owner ID isn’t supported.

  • At run time, when the flow user types two characters in the field, it shows up to five recent records whose Name field matches the query.
  • Dependent lookup filters aren’t supported.
  • During run time, the lookup component displays Search undefined if the lookup field defined in Field API Name isn’t on an assigned page layout. To display the correct text, add the defined lookup field to all of the source object’s page layouts that are assigned to running users.