Screen Flow is the only flow type that can be used to collect or display data in Salesforce. There are many input components that you can put on a screen. Besides the simple ones like text, number, or date, there are some input components that let the user select a value from the defined choices. Radio buttons, picklists, and checkbox groups can be used for this purpose. Unlike picklist fields that we know from the objects, these selection components can display records as choices too. So that it is possible to ask the user to select a record from a list. These selection components support multi-selection as well (multi-select picklist and checkbox group), which means that users can select more than one value from a list of choices. When the user selects only one record, then the screen component stores the value that you defined. So that you can use the selected value in your flow. However, when the user selects more than one choice, screen component stores all the selected values in a single variable. Since it is a variable of selected values separated with semicolon, it is not possible to loop through the selected choices, you have to convert it to a collection variable.
Read this article to learn more about the multi-select picklist screen component.
Convert Selected Choices to Text Collection
Even though flow doesn’t store the selected values in a collection variable, it is still possible to convert them to a collection variable.
Let’s assume that you have a screen that displays account records as choices. It displays account names as choice labels but stores the Ids as a text value.
When user selects records from this checkbox group, flow stores the selected record Ids in this format:
Since it is just a single text value, it is not possible to loop through them. In order to convert it to a text collection, follow these steps.
1- Creating a Text Variable and Assigning Values
First of all, create a text variable called SelectedIds and use an assignment element to assign the selected records to this new variable. Pay attention that Select_Accounts is the name of the screen component. Using the same assignment element, add “;” to the same variable.
At the end of this assignment, SelectedIds stores a value in this format:
As you can see, there is a semicolon at the end of each Id value. This will make it easier to extract the values since it follows a specific pattern.
2- Creating Formula Resources
In this step, you have to create two text formula resources.
This formula extracts the first record Id from the left side of the SelectedIds variable.
This formula removes the first Id value and its semicolon from the SelectedIds variable.
If you are using this logic for the Id values, then there is no problem. However, if you use it for other text values, you might want to change the RemoveFirstID formula. For example, let’s say that the selected text values are apple and green apple. Then this formula will remove the word “apple”, so that the remaining value will be “green”, which is not the selected choice. In this case, you can use a formula like this:
So at the end of these two formulas, you have the first Id value and the remaining values. Therefore, it is time to add the first value that you extracted to a collection.
3- Creating a Collection Variable and Assigning Values
Create a text collection variable and add another assignment element to add the FirstID into the collection. In the same assignment element, change the value of SelectedIds to the value of RemoveFirstID formula.
At the end of this step, you have a text collection that stores the first record’s Id and another text variable that stores the rest of the Ids with semicolon. You have to repeat this step in order to extract all of the values and add them into the collection.
4- Add a Decision to Check Remaining Values
In order to repeat step 3 for all the selected records, add a decision element that checks if there are remaining records in the SelectedIds variable. If there are, go back to the step 3.
This is the end of the steps to convert the selected choices to a text collection variable. After this last step, you can continue your flow with any action that you want to perform. Since you have a collection now, you can iterate over the items.
Read this post to see a real example of a flow that uses these steps.
Creating an Autolaunched Flow To Reuse as Subflow
You can build an autolaunched flow that receives a text variable and converts it to a text collection variable using these steps. Then, whenever you want to convert the selected choices to a text collection variable, just call this autolaunched flow as a subflow. Pass the text variable as the input and get the text collection variable as the output. By doing this, you won’t need to perform these steps in every flow.
These are the changes that you need to make:
- Create an autolaunched flow.
- Edit SelectedIds text variable and make it available for input. To make it more generic, rename it as SelectedChoices. When calling this subflow, you will pass your text variable into this input variable.
- In the first assignment element, remove the first line of the assignment that you did before, just add a semicolon at the end of this variable.
- Edit the RecordIDCollection variable and make it available for output. Rename it as SelectedChoicesCollection, so that it will be more generic. This will be the output of this flow.
- Rename the formula resources, so that they will be more generic as well.
FirstID –> FirstChoice
RemoveFirstID –> RemainingChoices
At the end, your autolaunched flow should look like this.
Let’s call this subflow from the undelete flow that you can see in this post.
Add the subflow element to the canvas, select this autolaunched flow, pass your text variable (in this case it is Deleted_Accounts) as an input. Manually assign the output value of the flow to your text collection variable (in this case it is FinalList).
At the end, your flow will look like this. By reusing an autolaunched flow as a subflow, you won’t need to do these steps again.
If you don’t have time to build it or still unsure about the steps, you can install the autolaunched flow from this link.