Lightning Flow: Use Record Choice Set in a Picklist
.jpg)
Default Values in Picklists
If you frequently use Flow Builder to build flows, especially screen flows, you are probably aware of the limitations of this declarative tool. One of the most frustrating is how default values work in picklists.Let me give you an example.You need to streamline the process of updating records of a complex custom object. For that purpose you are building a screen flow that takes the user step by step. A screen in the flow displays fields to be updated. Because the user is modifying an existing record, you want all those fields to be pre-populated with default values. This way, you can avoid getting null values, and you can provide sales reps with information about prior values.Everything works perfectly until you get to... the picklist.Ok, I made it sound way too dreadful than it really is. The issue here is that your default value will be displayed twice. First time, because you assigned it as a default value, and second time, as a part of the picklist choice set. It still works, but looks like a bug for an end-user.But don’t worry. There’s a way around it.
Using Record Choice Set for Picklist in Lightning Flow
The answer to this issue is to use a record choice set instead of a picklist choice set.To demonstrate how it works, let’s create a simple flow that users can use to update an account. Open the Flow Builder, and create a new screen flow.Our first element is going to be a screen. It is going to include a lookup component so the user can find the account they want to update.If you’ve never used the lookup component before, here’s a short explanation.When you configure the lookup element you tell Salesforce which existing field it should use. In other words, to add a lookup for accounts we must find a field on some object that’s a lookup to accounts. In our case we will be using a standard field on Opportunity:API Name: AccountLookupField API Name: AccountId (the API name of the field)Label: Please choose and account to update:Object API Name: Opportunity (the API name of the object)

The next step is going to use the ID from the lookup and use it to find the default value for the Industry field.Drag and drop the “Get Records” element onto the canvas and configure it to get the value from the “Industry” field. We are going to store in the “Industry” variable.

But this isn’t enough to create a default Choice. Industry field on Account isn’t a required one. This means we need to build a solution in case this happens.For this purpose, let’s create a Formula. It should display a short phrase if the value inside the “Industry” variable is Null.Formula:IF(ISBLANK({!Industry}), 'Choose Industry', {!Industry})

Next, let’s create a new Choice variable. Use the newly created formula as both the label and the choice value.

Now it’s time to configure the key element of the flow - our record choice set.First of all, we will use an object called Picklist Value Info. It stores data of all picklist values in your org.

To find the right one we need to filter it by EntityParticleId. In case of standard objects, this Id is the API Name of the Object and the Field, separated by a period, which leaves us with “Account.Industry”.If you are creating a record choice set for a custom object, you will need the custom object’s ID and the field’s ID instead of text values. So it’s going to look like this: “0150U100600qAPl.00N0U00000712KP”.

Now, to remove our default choice from the list of possible values the other criteria should be set up like this:

What’s left is to configure how each choice is stored:

If you need, you can store more values, but for a simple flow like ours that’s enough.With the record choice set properly configured, let’s drop another Screen onto the canvas.Get the “Picklist” component and add choices to it:1. The variable that contains the default choice - IndustryDefaultChocie.2. The record choice set we’ve just created - IndustryChoiceSetDon’t forget to assign the IndustryDefaultChoice as the default value.

In the last step of our flow, we are going to use the value from the picklist and update the record. We have all the information we need - the ID of the record, and the new value that should replace the original.

You should also add a final confirmation screen, so the user is notified that everything worked perfectly and the record is updated.

Before you click Activate, use the Debug Tool to test out if everything works correctly, and if it does, our work is done.
Conclusion
Record choice sets are very useful in creating picklists. Not just to properly configure default values, but to display a list of records as a list, instead of using a lookup. For the end-user picklists are often easier and quicker to use.Visit our blog for more articles on Salesforce Flow.