The Unofficial Lookup Component

screen shot 2018-02-11 at 8 38 20 pm

Introduction

This Lookup component complements the Lookup component built-into Flow by providing additional power and flexibility.

Install this Component Into Your Org

Installation (Unmanaged v2.32)

Installation (Managed v2.2)

Credits

This started out as the excellent Lightning Lookup control by Opfocus. Later it was enhanced by several members of the Flow community. The chief maintainer is currently Eric Smith.

Basic Attributes

Object Name: Type the name of the object that you want this control to lookup. You can use custom objects but don’t forget the “__c”

Display which Field: You get to choose which field actually shows up in the combo box and gets searched on. Usually you’ll just want to type “Name” here but you can use any text field

Field Label: This is the label of the control itself

Output which value?: You can separately decide which field should be extracted from the selected object and passed to Flow. For example, you might want to display Name but output Id because Id is easier to work with for some Flow Actions.

There’s also an Output Value attribute that’s used on the Output tab to map your selected value to a Flow variable.

Filtering the Lookup Choices

There are several powerful filtering mechanisms built into this component. You probably won’t need to use all of them at the same time.

Filter Using Flow Variables This allows you to specify the name of the specific field you want to filter on. It’s easy but basic.

Filter using a SOQL ‘where’ clause This allows richer filtering. See ‘Where Clause Usage’ below

Dependent Filtering

You can stick two of these components on a screen and have the second component filter on the selection set in the first component. See example 2 below

Multiple Dependent Filtering

You can include multiple Parent/Child groupings on a single screen by identifying each Parent component with a unique ID and specifying the related Parent ID for each Child component.

This component exposes the following attributes that can be set in Flow:

Attribute Reference

Basic Attributes

  • label=”I1_Object Name” This is the actual object that will be looked up
  • label=”I2_Display Which Field?” This is the field that will show up in the list box to represent a record. It defaults to “Name”
  • label=”I3_Field Label” This is just the label that appears next to the lookup control
  • label=”I4_Output Which Field as Value?” This is the field you actually want saved into the Output Value attribute. It defaults to Id so you can hav ean Id to use for lookups, but you may want to change it to Name or some other value.
  • label=”O1_Output Value” This will hold the value that is selected, for use downstream in the flow. If a value is provided as an Input parameter, it will be passed to the O1_Output Value Output parameter if no record is selected.

Advanced Attributes

  • label=”I5_’Parent’ or ‘Child’ Lookup?” If Child is entered, the filter value will be replaced by the value returned by the Parent lookup on the same screen.
  • label=”I6_Filter on which field?” This is the name of the field to filter the lookup on.
  • label=”I7_Filter Value” This is the filter value for the lookup.
  • label=”Where Clause” allows the input of a “where” SOQL style filter to limit which values are available for selection.
  • label=”Default” You can specify a default value placeholder in the lookup field
  • label=”Component ID” You can group multiple Parent/Child components on a single Flow screen. Add a unique value here for each Parent Lookup.
  • label=”Parent ID” For a Child Lookup, enter the Component ID of its Parent Lookup here to link them together.

Here’s an example of a configured component: screen shot 2018-02-11 at 8 48 18 pm

Default Values

OPTION 1

You can enter a default value for the input field (I2_Display Which Field). When provided, it will override any WhereClause and display the default value as Placeholder text in the input field. You will still need to select the dropdown then select the single value that is displayed. If you start to overtype the input field, the default value will be cleared and the WhereClause (if provided) will be reset and the field will act like a normal filtered lookup with search.

OPTION 2

Provide INPUT values for the following two parameters:

Default Value: (whatever placeholder text you want displayed in the input box – this should match the format of the I2_Display Which Field? parameter)

O1_Output Value: The value to be passed out through the O1_Output Value OUTPUT parameter if no value is selected in the input box (This should match the format of the I4_Output Which Field as Value? paraameter)

Example: Looking up an Account, defaulting to the Account Name of “ACME Company”. Assume the RecordId for ACME Company is stored in the flow variable vDefaultId.

[Input Section]

  • API Name: AcctLookup
  • Component ID:
  • Default Value: ACME Company
  • I1_Object Name: Account
  • I2_Display Which Field? Name
  • I3_Field Label: Account
  • I4_Output Which Field as Value? Id
  • I5_ Parent or Child Lookup?
  • I6_Filter on which field?
  • I7_Filter Value:
  • O1_Output Value: {!vDefaultId}

[Output Section]

  • O1_Output Value: {!vSelectedAccountId} (a text variable)

Where Clause Usage

Input is dependent on the fields available for the object selected for “Object Name”.

For example, if you wish to return only accounts of type “Vendor” or “Partner” you could enter the Object Name: “Account” and the where clause: “Type=’Vendor’ or Type=’Partner'”

Filtered Lookup Examples

Example 1: Lookup a Case filtered by an Account where the ID is passed into the flow variable vInputAcctId

screen shot 2018-04-15 at 10 17 54 am

Example 2: Lookup an Account and a Contact on the same screen and only select from Contacts from the selected Account

screen shot 2018-04-15 at 10 18 06 am

Source Code

View Source

————–

Changelog

3/7/20 – Fixed bug with Required not working (v2.32, Eric Smith)

10/29/19 – With the new release of Winter ’20, you will need to make sure you select the “Manually assign variables (advanced)” checkbox and set your output parameters to variable resources you have created in your flow.

7/1 Bug Fixes- Error handling for Required attribute & handle ‘ character in a field value (Install package v2.3)

3/22 Bug Fixes (Install package v2.2)

3/6 Bug fix (removed jQuery)

2/23 Misc changes.

8/11 Added ability to group multiple Parent/Child components on a single flow screen.  Eric Smith – August 2018

7/22 Added ability to set default: You can enter a default value for the input field (I2_Display Which Field). When provided, it will override any WhereClause and display the default value as Placeholder text in the input field. You will still need to select the drop-down then select the single value that is displayed. If you start to overtype the input field, the default value will be cleared and the WhereClause (if provided) will be reset and the field will act like a normal filtered lookup with search.  Eric Smith – July 2018

6/15 Another fix for the jquery issue. also fixed the default value for I4_Output Which Field as Value?

6/11 Another try at fixing the jquery issue. also Eric fixed a Parent Child bug.

6/3 the Summer version was also published accidentally without jquery! fixed now.

5/7 released new managed package version with some bug fixes

4/15 Published v1.6 adds two different ways to filter the results (where clause and specific field) and allows Dependent Lookups, courtesy of @datapharmer and @ericrsmith35

2/28 Published V1.4 Fixed missing JQuery in package to eliminate “Hover” bug

ext

Sample Component Setup

The flow screen image at the top of this page includes 5 lookup components.  The Primary Contact(2) is a child of the Bill To Account(1) and the Delivery Contact(4) and Service Address(5) are children of the Deliver To Account(3).