A multiselect picklist field allows users to choose multiple values from a list of predefined choices. Although multiselect picklist fields have many limitations, they are still widely used. In many situations, you may need to perform actions for each selected value. Multiselect picklist fields store the selected choices separated by semicolons. However, since it is just text and not a collection, it is not possible to loop through the selected values directly. Here is how to convert a multiselect picklist into a text collection in Salesforce Flow.
How to Convert Multiselect Picklist into a Text Collection in Flow
1- First, create a text variable and use an Assignment element to assign the multiselect picklist field's value to this variable. Since all the values are separated by semicolons, add another semicolon at the end to ensure that each value is followed by a semicolon. Pay attention that SelectedValues is a text variable and not a collection.
2- Now, it is time to create formula resources to extract the values.
Create a formula resource called FirstValue. This formula stores the first selected value (any value before the first semicolon).
TRIM(LEFT({!SelectedValues}, FIND(';',{!SelectedValues})-1))
Create another formula resource called RemainingValues. This formula resource removes the first value from all the selected values.
TRIM(SUBSTITUTE({!SelectedValues},{!FirstValue}+';',""))
3- Create a text collection and use an Assignment element to add the FirstValue to this text collection. Then, in order to remove the first value from all the selected values, make SelectedValues equal to RemainingValues.
4- Repeat the previous step until there are no values left. Add a Decision element to check if there are more values remaining.
If there are more values (the "Yes" outcome), go back to the previous Assignment element. If there aren't more values, it means you have successfully converted your multiselect picklist into a text collection.
Here is the result of the flow. As you can see, it has converted the multiselect picklist into a text collection. Now you can loop through the values and perform any action that you want.
Convert Any Delimited Text into a Text Collection
Just like in the previous example, it is possible to convert any delimited text into a text collection. The only difference is the delimiter; instead of a semicolon, we can use any delimiter in our formulas.
Let's build an autolaunched flow that receives the text values and the delimiter.
1- Create 2 text variables called TextValues and Delimiter. Make sure that you mark them available as input, so that you can pass these values when calling the flow as a subflow. Also, create a text collection variable called TextCollection and mark it available as output. This will be the output of the flow.
2- Create formula resources like the previous example. However, this time you need to use the Delimiter variable instead of a semicolon.
FirstValue
TRIM(LEFT({!TextValues}, FIND({!Delimiter},{!TextValues})-1))
RemainingValues
TRIM(SUBSTITUTE({!TextValues},{!FirstValue}+{!Delimiter},""))
3- The rest of the steps are the same. There is only one small difference in the first Assignment element. Since you will already have the values in the TextValues variable, you just need to add the Delimiter.
POC
To prove that it can work with any delimiter, let's debug the flow with text values separated by smileys.
There are 3 values (Yumi, Salesforce, Salesforce Time) separated by smileys. Let's debug the flow with these input parameters.
As you can see, the flow converted the smiley-separated text into a text collection.
Installation Links
If you don't have time to build it or still unsure about the steps, you can install the autolaunched flow from these links.
Use this link to install in production or developer edition environments.
Use this link to install in sandbox environments.
Leave a Reply