+ 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.