function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
GailGail 

How do I assign multiselect picklist values to a collection variable in a flow?

I have a flow where I tried to add the multiselect picklist values to a collection variable but this simply added all values as one value (e.g. "x;y;z" rather than "x";"y";"z". How do I add these as individual values to the collection so that I can use them in a loop? 
Best Answer chosen by Gail
GailGail
I ended up doing a loop to select the items one at a tiime and process one at a time. Could find no way to assign to a collection variable. 

All Answers

GailGail
Thanks but that doesn't actually solve my issue (and is what I'm currently doing). That passes the ids into one variable - what I need to do is create a collection variable. I'm going to try to use the parsing code mentioned in the comments and see if I can then assign the parsed values to a collection variable. 
GailGail
Tried that but I can't see how to get an output of a list from a process plugin....
 
GailGail
I ended up doing a loop to select the items one at a tiime and process one at a time. Could find no way to assign to a collection variable. 
This was selected as the best answer
Joe CookJoe Cook
Hi Gail. I ran into the exact same problem, and I'm surprised it doesn't come up more in these discussions. Unless I'm missing something really obvious, it seems like a huge limitation to not be able to assign a multi-select field to a collection variable OR be able to loop on a multi-select field. What's the point of having a multi-select field if you have to write code to parse the values?

I found a not very intuitive work-around, but it works:
  • I used a fast lookup to create an sObject collection variable, which basically replicates the dynamic choice that populates the multi-select checkbox field
  • After the user makes his/her choices (populating the multi-select field) I loop through the sObject collection variable
  • The loop connects to a decision
    • If the multi-select field contains the [sObject variable].Id (or whatever field you're using as the value of your dynamic choice)
      • then ... (in my case I create a record)
      • then connect back to the loop
    • If the multi-select filed does not contain the [sObject variable].Id (or whatever field you're using)
      • then connect back to the loop
I hope this helps. I'm happy to discuss more if what I described doesn't make sense.


 
Paul WulffPaul Wulff
Thanks a lot for the hint, Joe Cook! Only approach that allowed me to loop through the selected objects based on a dynamic choice multi select screen input. 
Chris LanceChris Lance
Joe Cook, brilliant!  

I came up with a solution similar to yours, but I was apparently overthinking it was I was trying to assign the multi select dynamic choice values to a collection variable first (where you can see them as semi-colon delimited IDs) and then loop the decision against that collection variable - going this route worked great as long as I only selected a single value, but any combination of multi selected values ended in no matches.  So I nixed the collection variable and linked the loop decision directly against the dynamic choice as you suggested and BINGO.  

I also want to echo what Joe wrote:
"Unless I'm missing something really obvious, it seems like a huge limitation to not be able to assign a multi-select field to a collection variable OR be able to loop on a multi-select field. What's the point of having a multi-select field if you have to write code to parse the values?"

+1
Ian AD CarswellIan AD Carswell
Joe,

Thank you your solution works great. It took me some fiddling around to get it to work.
Initially in the decision I try to match against the dynamic choice does not return any matches:

Matching SObject Collection Variable against Dynamic Choice
But if I match against the multi-select choice field which contains the dynamic choice it worked like a treat.
Matching SObject Collection Variable against Multiselect Field

Woot!

Many thanks.
 
Indira Damodaram 1Indira Damodaram 1
I had a similar situation and found Joe's solution really worked in my case! Thanks. 
 
Kevin ShivelyKevin Shively
I was about to try Joe's solution when I found what seems to me to be a really slick alternative. I think you could adapt the following Flow procedure to do what we're all trying to do:

http://automationchampion.com/2015/02/03/add-record-to-multiple-chatter-groups-parsing-multi-select-picklist-fields-flow/
Raja Bipin Chandra  M BRaja Bipin Chandra M B
Mr. Joe, your workaround worked like a charm. Thankyou so much!

Best Regards,
Raja
JoeyLenJoeyLen
Also want to chime in on Joe's workaround.  I have spent hours trying to get this to work and got Joe's solution to work in about an hour.
Thanks.
Collen Mayer 6Collen Mayer 6
Joe: this worked great.  Never could have come up with it by myself.  Thanks!
tobias.brandtobias.brand
Great idea, Joe. I felt, it must be possible. Thank you so much.
Joshua FeistJoshua Feist
I made one of these to allow users to delete multiple attachments on a case. Here's a gif of the Flow: https://media.giphy.com/media/3o7bu988bdyeXmkUOA/giphy.gif
Jack VolkovJack Volkov
This Salesforce Sidekick article by David Litton, Parse a Multi-Select Value in Visual Flow (https://salesforcesidekick.com/2016/11/07/parse-a-multi-select-value-in-visual-flow-unmanaged-package-included/),  provides a flow that can be called from other flows to parse a multi select picklist value.
  1. Download David's managed package
  2. In your flow, create a normal text (aka string) variable to hold your multi select picklist value
  3. In your flow, create a collection variable
  4. Call the "Parse Multi-Select" unmanaged package flow from your flow, using the string variable above as the input, and collection variable as the output
  5. Voila, your multi select picklist is now parsed out as an actual collection (in your collection variable)
Jimmy WenhamJimmy Wenham
Jack I also used this and now I want to use collection variable to populate a field on record create - how do I do that?
Jack VolkovJack Volkov
@Jimmy - did you already follow the 5 steps listed above?

6.  Loop through the collection variable populated in step 5 and assign the current value to a new variable using the Loop element.
Parse-Loop-Elements
7.  In the Record Create element, use the current value variable to assign a value to a field for the new record.
User-added image
David Walker 66David Walker 66
Another way that has worked for me, not sure if it's simpler: 
1. Ensure that your screen element stores the ID of the selected 
2. After user (multi-)selects, assign the Screen Element variable to a Text variable.  The Text variable will now contain all the ID's of the selected records selected (assuming the Screen element is a record choice set - but it would work for other choice sets also).
3. Use text formulas & assignment element to extract the first 18 digit ID code, and use that code in an assignment/create/lookup etc element, as needed for your code.
4. Use text formulas & assignment element to remove the retrieved ID plus semi-colon plus space from the Text variable.
5. Use a Decision element to determine if the end of the text variable has been reached (a quasi loop), and either return to 3 again, or exit.
VIBHOR GOEL 47VIBHOR GOEL 47
Checkout this latest way to do this without need of doing this using a downloadable apex action component that Parses and converts Multi Select Picklist values in a Flow to a Collection Variable here by Accidental Coder SF : https://www.accidentalcodersf.com/2021/01/parse-multi-select-picklist-values-flow.html
Lotte WissLotte Wiss
Recently, I've become interested in a new kind of online income. Copywriting. I hope that my future will be related to this direction, and if not, I will just move on. Into the bright tomorrow of my extraordinary life.
Try you will lioke https://www.slotozilla.com/free-slots/kitty-glitter it really good 
George WakedGeorge Waked
Wow, all hail Joe Cook. Only thing on the internet that I could find to solve this problem.

I was trying to update one field on several records that the user selects from a multi-select picklist. Joe's solution worked. I did 2 assignments in the loop, one to update the field I want, and another to assign the record from the current loop to a third collection variable. Then I did an "update records" on that third collection variable.

Worked like a charm! Thanks again.
William AnnistonWilliam Anniston
it happens a lot :) https://tenor.com/view/obama-finger-guns-happy-fingerpoints-gif-5118627
Stanleey NewmanStanleey Newman
i think you need to ask some experts about your problemю
Usually technicians work with almost any company, the company I work for has them, you can contact them by going to the company website. I leave the link here 7bitcasinoreview.com 
HijlkoHijlko
To get the number of selected multi picklistvalues of (let's say the API name of your choice set = ) "Picklist" you have to create a formula, type Number, no decials, and give it a name like "NumberOfChoices". The formula:  LEN( {!Picklist} ) - LEN( SUBSTITUTE( {!Picklist},';','') )+1 
What it does is get the length of the string of Picklistvalues and subtract the length of the string of Picklistvalues where the separation character of the values ";" is replaced by an empty string "" and adds 1
Example1:
Picklist choice value = "Choice1" 
Length of "Choice1" = 7 (a)
Length of "Choice1" where ";" in "Choice1" was replaced by "" = 7 (b)  (it was not found so there was nothing to replace)
Add 1
a - b + 1 = 7 - 7 + 1 = 1
There is 1 choice selected

Example2:
Picklist choice value = "Choice3;Choice4;Choice6;Choice9" 
Length of "Choice3;Choice4;Choice6;Choice9" = 31 (a)
Length of "Choice3Choice4Choice6Choice9" where ";" in "Choice3;Choice4;Choice6;Choice9" was replaced by "" = 28 (b)
Add 1
a - b + 1 = 31 - 28 + 1 = 4
There are 4 choices selected

When you add a choice from your picklist to a record variable and recordcollection variable, you want to count the added choices so you can stop adding choices when the number of added choices is eqal to the number of selected choices.
For this you create a variable, type number, no decimals and give it a name like "NumberOfProcessedChoices". Default value 0
Create another variable, type Text, and name this like "AddedChoices"
Create a formula, type Text, Name "ChoicesToProcess". Formula:  IF( LEFT( RIGHT( {!Picklist}, LEN( {!Picklist} ) - LEN( {!AddedChoices} ) ),1) = ';' , 
                                                                    RIGHT( {!Picklist}, LEN( {!Picklist} ) - LEN( {!AddedChoices} )-1),
                                                                    RIGHT( {!Picklist}, LEN( {!Picklist} ) - LEN( {!AddedChoices} ) ) )
Create a formula, type text, Name "ChoiceToProcess".  Formula:  If( FIND( ';' , {!ChoicesToProcess}) = 0, {!ChoicesToProcess}, left( {!ChoicesToProcess} , find( ';' , {!ChoicesToProcess} ) -1))                                                            )
Create a formula, type Text, Name "AddChoice".        Formula:  If( LEN( {!AddedChoices} ) = 0, {!ChoiceToProcess}, {!AddedChoices} + ";" + {!ChoiceToProcess} )

In your flow, before you start adding choices from your picklist to a record variable and recordcollection variable it's a good thing to:
- assign the value 0 (again) to this variabe ("NumberOfProcessedChoices")
- assign the value emptystring to this variabe ("AddedChoices")

Create a variable, type Record, checkbox "allow multiple values" NOT checked, choose the object where you want your choice to be added to, let's say you name it "SingleChoiceRecord" 
Create a variable, type Record, checkbox "allow multiple values" MUST BE checked, let's say you name it "ChoicesRecordCollection"

After the assignment you add a decision, let's say you call this "CheckNumbersToProcess". When "NumberOfProcessedChoices" LES THEN "NumberOfChoices" then go to
Assign the needed fields AND your formula "ChoiceToProcess" to the corresponding fields in your record variable "SingleChoiceRecord", 
then you ADD this recordvariable "SingleChoiceRecord" to the recordCollection Variable "ChoicesRecordCollection"
After this you add an assign element: 
- Assign a new value to the variable "NumberOfProcessedChoices" ->  ADD   ->  1
- Assign a new value to the variable "AddedChoices" ->  Equals ->  your variable "AddChoice"  
Go back to the decision "CheckNumbersToProcess". When "NumberOfProcessedChoices" is still less then "NumberOfChoices" it will add the next choice, and so on
When "NumberOfProcessedChoices" is equal to "NumberOfChoices" you create the records from the recordcollection
User-added image
 
Only PromosOnly Promos
Indeed, earning has become much more difficult, especially in traditional types of business, as many have switched to online work, which has become very competitive and even dominant. Most people want to earn money for an apartment or house, but this naturally requires a good and high-paying job to pay off the loan. All people have basically looked for and taken on a job to make money, and it is only natural that a full-time job gives you the opportunity to earn much more than a part-time job, so I only support a full workload at work, although I have and additional earnings, which significantly helps me to make money, this is when I play on the online casino https://jennycasino.com/casino-ratings/ and on slot machines where time flies by. Therefore, I think it is better to try to buy your own home yourself.