Parsing An Object’s Multi-Select Picklist Selection/(s) To Use In A Visual Flow

I recently worked on an interesting requirement which demanded grabbing the Multi-Select Picklist selection/(s) from an object’s field and then showing them in a picklist as select-able options on a Flow screen. So this is what the user flow looks like:

  • User makes selections on an Multi-Select Picklist on the main object.
  • User then clicks a custom button on this object which takes him through a Visual Flow.
  • Within this Flow, the User is shown a screen with another picklist (single select or multi select).
  • This picklist shows values from the Multi-Select Picklist selections chosen in the first step. Which means it has to a Dynamic Record Choice as its source.
  • Further logic is executed based on the picklist item selected.

The parsing idea was suggested by an active success community member David Litton (thanks!) and that was enough to get me started. Here is the what the final flow looks like:

 

Flow Designer

Flow Designer

 

Let’s go through the elements one by one and how we utilized them:

  1. Record Lookup
    We are launching our flow using a custom button on our Test Object so a record lookup element is used to find the record and store our Multi-Select Picklist selection/(s) in a text variable. Now we could have passed the MSP value directly via the button URL but I had to store a lot of other record values as a part of the original requirement hence the Record Lookup element.RL
    Objective: We store our raw unparsed Multi-Select Picklist selection/(s) in a text variable. In case you are curious, this is what it looks like:Sel1Sel2
  2. Assignment (Remove Square Brackets)
    Towards our first step in parsing the values, let’s get rid of the square brackets. Once the square brackets are removed, we assign the values to another variable.Ass1

    Bracketless
    The above formula removes the square brackets and adds a semi colon (;) at the end of the string. The semi colon would be our delimiter aid for the parsing.
  3. Decision
    We will be extracting the needed SuperHero from our {!vSelectedSuperHeroes} variable one by one and continue doing this until there’s nothing left in it. An empty  {!vSelectedSuperHeroes} variable means all super heroes have been extracted from the source string and we can proceed with the rest of the logic in the Flow.Decision
  4. Assignment (Add to Usable Collection)
    This element is our first step towards forming our collection of Parsed Super Heroes. What we do here is that take out a Super Hero from the {!vSelectedSuperHeroes} variable and then assign it to a string collection Flow variable {!vParsedHeroesCollection}.Ass2
  5. Assignment (Remove from Original Collection)
    In this step, we remove the {!OneSuperHero} + “;”  string from the  {!vSelectedSuperHeroes} variable and move towards emptying it out.Ass3The {!RemoveFirstPG} formula field is what we use to remove the superhero one at a time from the {!vSelectedSuperHeroes} variable.Form
  6. Loop (through the Parsed Heroes Collection)
    We now loop through our Parsed Heroes Collection variable in order to create a Custom Setting record for each Super Hero selection.Lop
  7. Record Create (Create Custom Setting Records)
    For each parsed value, we create a custom setting record.CustomThis is what our final outcome looks like:SHAnd we are done! Now why did we put the parsed values into a Custom Setting? Well we might need to use the selected Super Heroes from our Multi-Select Picklist to create the items for a Picklist on a Flow screen which must use a Dynamic Record Choice as the source. Creating custom setting records helps us easily achieve that. You could always do a Fast Delete at the end of the full flow to remove the custom setting records once their purpose is served.

 

Wasn’t that easy? I can already think of a ton of ways to use this for other related implementations and hope that so do you. I know that there might be better ways to do this or even optimize what I did and will continue improving this logic if I can think of something creative. If you designed such a logic in flow using other methods, I would love to hear about it in the comments below.

  • Balaji Srinivasan

    Mayank,

    Had a question – Is there a way to troubleshoot the steps in Visual workflows at each and every step. Example, is there a way for me to see the values in the steps – Assign to Usable collection, Remove from Original collection — kind of like using System.debug in our code to see if that the formula is returning the correct value. Pl advise.

    • Mayank
      • Balaji Srinivasan

        Thanks Mayank. One more question. Even after parsing all the heroes correctly, the decision step keeps looping and adds empty items to the list. When I display the vSelectedSuperHeroes on the screen it’s empty, but when I try to leave it the way you did or even tried comparing it with {!$GlobalConstant.EmptyString} in the decision step, it’s still adding empty items to the collection variable vParsedHeroesCollection – ParsedSuperHeroes:[Spiderman,Captain America,Iron Man,,] (note the commas at the end of the list), what am I missing here?

        • Balaji Srinivasan

          I was able to get this fixed. Thanks for your help !

  • Kari Moser

    Hi Mayank!

    This is very cool! But I think I’m missing a step. Could you provide details on how you set up the vParsedHerosCollection & the OneSuperHero variable?

    Right now the OneSuperHero isn’t set to anything, so my flow just loops through and assigns a blank value and it errors out (because there is an endless loop).

    I’m new to loop and collection variables, so any guidance you could provide would be awesome! Thanks!

    • Mayank

      Kari, were you able to sort this out? Please see my response here:
      https://success.salesforce.com/answers?id=9063A000000iOWb

      • Kari Moser

        Yes. Thank you!

      • RITESH SHARMA

        Hi Mayank, Looks like the solution you provided here is still not complete. If we add the {!OneSuperHero} formula to remove rest of the items, it leaves us with one value from selection to begin with and we cannot assign formula to collection. please help here!!

  • Hauck APP

    Hey Mayank,

    thanks for sharing this!

    How are these formulars working? Is there a way to put a formula to a specific step or execute the formular at step x and step y?
    I didn’t find the trick yet :/

    Thanks,
    Melf

  • sjm

    Hi Mayank
    Thanks for going to the trouble for posting this step by step. I think this might be the solution I am looking for (well a big part of it). We have a custom field Contact_Type (uses a multi-select picklist)in Contacts. One of the types is Member. We want to automate it so that anyone who is over 90 days late has Member removed from their Contact _Type and has Member-Ex added. I wanted to try keep this in Visual Flow rather than do a Trigger.

    In your opinion, that should be possible…yes?
    You solution above provides the ability to parse the Contact_Type selections for a Contact. I just have to work out how to replace one of them and save it back to the Contact record. Cheers

  • Holly Havelka

    Hi Mayank,

    I am trying to utilize your solution, but its only creating a record for the first parsed value in the collection vs. creating a new record for each value: Batman vs. Batman, Hulk, Superman.

    Any thoughts on what I might be doing wrong?

    Great post.

    Holly

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

© 2017 Succeed With Salesforce | Website by Tonevski.com

Log in with your credentials

or    

Forgot your details?