UPDATE: See Default Flow Picklist Value Without Duplicates In Flow Builder for how to do this in Flow Builder.
Flows are great but there are some quirks. One quirk is that a picklist input field can’t be prepopulated with the existing picklist field value from a record. There are some workarounds:
- Salesforce Flow – How to Default An Existing or the Current Picklist Value
- FLEXIBILITY IN FLOWS: CUSTOM SETTINGS AND DYNAMIC PICKLISTS
- Default Variables on Choices in Visual Flow
and there’s even an Idea: Flow – Pre-populate choices with dynamic values (variables).
The workarounds are good but one minor nuisance is that they cause the current picklist value on the record to be duplicated in the dropdown list.
Below is my solution that doesn’t have a duplicate option by using the PicklistValueInfo standard object in a Dynamic Record Choice.
High-Level Solution
- Query the record with the desired fields including the picklist field(s) using a Record Lookup or Fast Lookup.
- Create “Current Picklist Formula” that has an expression like “If(IsBlank(record.PicklistField), ‘Select an option’, record.PicklistField) so the formula can be used to dynamically use either the record’s picklist value if there is one or ‘Select an option’ if it’s blank.
- On a screen, create a picklist input with the following settings:
- Choice – Use the current picklist formula as the label and stored value
- Dynamic Record Choice – Use the PicklistValueInfo standard object to query all the picklist values except the currently selected value.
- Set the Default to the “current choice”.
Industry Example
Let’s create a flow that allows one to quickly update the Industry field on an account record in Lightning.
Create recordId Variable
Query Account Record
Use a Record Lookup or Fast Lookup to query the account or desired record using the recordId variable. In the screenshot below, a Record Lookup is used. Note how the current industry is stored in the “Current_Account_Industry” variable.
Create Industry Default Choice Formula
Now, let’s create the “Industry_Default_Choice” formula that uses
- The “Current_Account_Industry” variable if it’s not blank.
- “Select an Industry”, otherwise.
Create “Selected Industry” Variable
Another quirk that drives me crazy is having to create a variable for a dynamic record choice to be saved to before it’s created. That’s needed because a dynamic record choice doesn’t allow one to create a variable on the fly like most other places.
Create a “Selected_Industry” variable like:
Create the Industry Input Field
Let’s start with the finished “Industry” dropdown list input field.
To create this, add a Dropdown List Input field to the desired screen.
Next, create a new “Choice” through the Add Choice link using the following settings:
The “Industry_Default_Choice” formula is used for both the Label and the Stored Value so they both can be dynamic. I.E. if the account has an industry, then it’ll be defaulted. Otherwise, “Select an Industry” is used.
Next, create the “Industry_Picklist_Choices” Dynamic Record Choice with the following settings:
Let’s break this down a bit. The “PicklistValueInfo” standard object contains all the picklist values for every picklist field on every object in the org. The “EntityParticleId” column has values in the format of <Object_API_Name>.<Picklist_API_Name>. In this example, the “Industry” field from the “Account” object is used so “Account.Example” is used to query all the Industry picklist records. Note: If it’s a custom picklist field, see the Custom Picklist Field Considerations section below to determine the correct EntityParticleId value.
The second filter of “Value does not equal {!Current_Account_Industry}” will exclude the current industry, if there is one. If no industry is selected, all the active Industry picklist values are shown.
Now, simply use the {!Selected_Industry} variable as needed in the flow to do something with the selected value.
Benefits
- The list of industry picklist values are dynamic and change automatically without having to alter the flow as the Industry picklist values change.
- The inactive picklist values are automatically excluded.
- There’s no duplicate value in the list.
Limitations
- The picklist values available per record type aren’t honored. The user sees all the active picklist values.
- 200 is the limit of how many picklist values can be shown in a picklist. If there are more than that, they aren’t shown. Kudos to Sharath Prabhu for sharing that.
Custom Picklist Field Considerations
Andy Kallio mentioned in this Success Community Post that custom picklist fields have an EntityParticleId like “Object.00NE0000000Y1CD” instead of “Object.Custom_Picklist__c”. To determine the correct EntityParticleId to use, query the EntityParticle object filtering by the desired object, find the desired field and then use the FieldDefinitionId value. Here’s the template SOQL query to use:
SELECT EntityDefinitionId, QualifiedAPIName, FieldDefinitionId
FROM EntityParticle
WHERE EntityDefinition.QualifiedApiName = ‘<SObject_Name_Here>’
After the correct FieldDefinitionId is found, use that in the Dynamic Record Choice so the correct picklist values are used. If you have a better way to get the field definition id, please let us know in the comments.
What did you think of the solution?
Hi,
Thanks for this solution! It is exactly what I need, however, it is working well only up till the step where I create a dynamic record choice. I am trying to query a custom object, so I set —-. This does not return any values to the picklist. All I see is the default ‘CurrentValue’ that I set. Could there be something else that is going on?
Make sure the EntityParticleId is in the form {Custom_Object_Api_Name}.{Picklist_Field_API_Name}. For example if you have a custom object named Example__c with a picklist api name of Picklist__c then the EntityParticleId should be “Example__c.Picklist__c”.
Another thing I wonder is if security is restricting the values. If you run the flow as a system admin, can you see the picklist values? If you can as a system admin but not as a non-admin, then it’s probably security related and this solution may not work so one of the others listed in the article should be explored.
Hey,
nice work done here.
But I am facing an issue.
The Selected_Industry is empty in the following scenario :
-an industry is set on the account – really important
-the user reaches the screen where the picklist is defaulted to the account’s industry as per the purpose of the article
-the user leave the picklist untouched since this is the value he/she wants – really important – and clicks Next
-when used, the Selected_Industry variable is blank
I think it is blank because it is only set by the dynamic choices part of the picklist in the “Assign the record fields to variables” section, but the default choice never sets the Selected_Industry variable with its own value.
The solution here would be to create a formula that checks :
if the Selected_Industry is blank, take the default value in Industry_Default_Choice, otherwise, take the Selected_Industry.
But I may have made a mistake… What do you think ? Are you certain it works for you in the scenario I described ?
Thank you
Julien,
I think you’re correct. The selected value would be blank so perhaps the formula needs to be updated. Did it work when you updated it?
Hi Luke,
Very helpful article. Thank you so much! I would like to mention a couple of things:
1 –> I faced some inconsistencies when saving a picklist value. At the end it was saved with other than the selected one (like random). And I realized I didn’t have the PicklistValueInfo ordered, so I ordered them in an ASC way. That solved my issue.
2–> Right now I have another PicklistValueInfo for Countries. There are a lot of values. But for some reason the Record Choice Set doesn’t bring any value, and of course, I made sure it has the right EntityParticleId “Object.00NE0000000Y1CD” value in the condition. Very, very weird. I don’t know if the issue might be caused for the bunch of values there are.
I wish you can have an idea about #2. That would be awesome.
Final question: Have you figured out a way to default select for Picklist Multiselect?
Thanks a lot!
Ernesto,
For #2, I wonder if it’s a permissions issue where the running user can’t see the field? Try running the flow as a System Admin and see if that helps and ensure all the users have access to the Country field. I also wonder if it’s because State & Country picklists are enabled and that’s interfering with where the values are originating?
For #3 multipicklist, I have not tried.
This is a wise and helpful article.
However, I’ve tried to do this solution in the new Flow Builder, and I had to change the formula to :
IF(ISBLANK(TEXT({!Opportunity.BillWhen__c})),”–None–“,TEXT({!Opportunity.BillWhen__c}))
Still with no luck, only the value which is stored in the related object is showing up. The rest of the values of the dropdown not. Could you please help?
Thank you.
Frank,
It seems like Salesforce changed some things up when the new Flow Builder was released. For example, I noticed that the Object Ids are now formatted like record ids instead of with API Names. See if the Opportunity object id has changed now.
I also did an updated version of this using the new flow builder at https://metillium.com/2019/05/default-flow-picklist-value-without-duplicates-in-new-flow-builder/. Perhaps that’ll help.
Thank you Luke for the workaround.
If the picklist has a lot of values (my guess is more than 200) then you need to limit it (to say 200) when you define the conditions for the dynamic choice (PickListValueInfo). Then the values will be shown on the flow screen.
So, it is not because it is inconsistent but because pick lists have a max value limit of 200.
Sharath,
Thanks for sharing that info! I didn’t know there was a limit of 200 choices. I’ll update the article to convey that.
Hi Luke,
This has been a huge saver. I have been using this in a Flow in our Partner Community, and recently it stopped working (no changes were made to the Flow), reporting this error in the Admin email log:
“Error element Furniture_Type_Lookup (FlowRecordLookup).
This error occurred when the flow tried to look up records: sObject type ‘PicklistValueInfo’ is not supported.”
Internal License Salesforce users are not impacted; it still works for them.
Do you know if there is a way to check object permissions for the Picklist Value Info object for external user Profiles?
Hey,
i implemented the same . it was working fine until few days before i am receiving this error msg
“java.lang.IllegalArgumentException: Multiple entries with same key: ”
please guide as i have no clue how come keys are same for the values.
Suvojit,
Perhaps this was a bug coming from the Summer Release? Not sure why there’d be multiple entries with the same key. Are you still getting this error? If so, try submitting a Salesforce case and see what they say.
Hey Andrew,
Glad this has been helpful 🙂 Sounds like Salesforce made a change in Communities that enforces license permissions with the “PicklistValueInfo”. I’m honestly surprised they were able to see them before. AFAIK PicklistValueInfo is an internal System object and one that can’t be granted permissions directly so I’m afraid you’re outta of luck with this solution.
Hi *,
it seems that Object.00NE0000000Y1CD is not working for Picklist Value Sets.
Any idea, how we can restrict these values?
Thx!
James,
Thanks for the heads up. Link fixed.
Luke
Found this SOQL query worked best for me:
Select Id,DurableId,QualifiedApiName,EntityDefinitionId from FieldDefinition WHERE EntityDefinition.QualifiedApiName = ‘OBJECT API’ AND QualifiedApiName = ‘Field API’