Lightning Flow Designer: Set the Default Value in the Lookup Component

The Winter ’20 Salesforce Release added a highly sought after piece of functionality – the ability to lookup a record within a flow screen.  This eliminates the need to build a workaround solution for users to find records.

It works almost like every other screen component: just drag and drop it onto the screen where you want it then configure it to lookup the field/object you want to find.

he New Screen window shows a Lookup component labeled Account for This Opportunity. Object API Name is Opportunity and Field API Name is AccountId.

It appears in the screen as a lookup field would appear normally on a record.

The Sales Wizard has a lookup field called Account for this Opportunity.

I’ve recently used this lookup component in a request form and ran into some difficulty meeting one of the business requirements.

Can you add a field called “Requestor” and have it pre-populate with the user that is submitting the form?

Seems simple enough, right?  I thought so too.  The problem I had was that the documentation and the help bubble text isn’t very clear.  If you look at the help article for the lookup component, there is a configuration field listed for Default Value (left image in red), but that doesn’t exist in the actual component UI (right image).

ConfigurationFields.png

Was I missing something?  Did I miss a setting or need to pass a value into the screen component?  No, I wasn’t missing anything.  The help article just has incorrect information.

At this point I had to reach out to the community because I was stumped.  The simple answer is if you want to pre-populate a value in the lookup component, you need to set the default ID into the Record Id field in the component.

I don’t think I would have ever figured this out without assistance, which is entirely why I’m writing this post.  Let’s look at the description of this field on the component.

RecordIdDef

Does that mean the value of record that was selected in the lookup component? Or is this where you set the variable to track which record was selected?  It’s a very nebulous description for this field and needs to be changed to be crystal clear.

flowglobalvars
All the Global Variables accessible in Flow

Let’s go back to my requirement: pre-populate the lookup with the current user.  Since we now know where to set the value, we need to look at how we find the current user id.  Since it’s a screen flow, you can’t easily pass in a variable like you can if the flow is called via Process Builder.  Most resources in flow only allow users to pull in Global Variables from the flow itself.  The only resource that will allow you to find details from Global Variables outside the flow is a Formula Resource.

Global Variables behave like any other record lookup, except they pull values about the current session.  They’re pretty useful and you should review if you are unfamiliar with them.

Anywho, I created the formula to find the Id of the current user.  I start my formula resources with a “f” for easy reference.  Notice how simple the formula is: {!$User.Id}.

fCurrentUserId.png
Formula Resource to find the Id of the Current User.

Once the formula field is built, I set it in the Lookup Component Record Id field and Voila!  The current user record is pre-populated into the Requestor field in the form.

RecordIdInUse
The final solution that meets the business requirement.

 

Since the solution is really simple, I’ll repeat it again here.  Hopefully this helps someone else avoid a minor headache.

To pre-populate a record in a Lookup Component in Flow, you need to set the value in the Record Id field within the component.