Parse Multiselect Picklist Values And Create Related Records – Flow

Autolaunched flows and record triggered flows are in the game now. They have taken over a lot of apex functionalities, enabling admins to get most of the job done.

Here’s another trending scenario I came across and thought of putting it here.

Use Case:
You have an Industry Multi-Select Picklist on Account, and a custom object called "Industry" with as many record types as the values in the picklist field. Ex: Agriculture, Banking, Finance, etc.

When an account is created or updated with one or more Industry values, an equal number of Industry records(custom object) with the respective record types are automatically created. 

Now we can achieve this scenario in multiple ways, but here we choose flows.

The flow itself has two parts to it.

  • Parsing the selected multi-select picklist values.
  • Creating as many related records with correct record types.

We can parse the picklist values in two ways. Using formulas and apex.
In this blog, we are using a couple of formulas to strip down the extra characters and construct what we need.
If you are looking for sorting it with apex, I shall put so in my next blog!

The Big Picture

Let us now get into the details.

Industry Field (multi-select picklist) on Account

I created a custom multi-select picklist field (Industry__c) on Account and copied all the values from the standard Industry field of Account object.

Industry Object and Record Types

I created a custom object called Industry__c, Master-Detail relationship with Account and added in the following record types.

Flow Setup

Glimpse of all the variables used in the flow.
Step 1:
Step 2:

We simply assign the selected picklist values into a variable, rawMultiSelectPicklistValues (TEXT). We do so because this variable is to be used in the formulas in the next steps and directly using $Record.Industry__c is not allowed.

The values in rawMultiSelectPicklistValues would look like Agriculture;Banking;Finance

Step 3:

The selected picklist values are separated by semicolon ; except for the last value. So we are using a formula formulaRemoveBracketsAndAddSemiColon (TEXT) to add a semicolon after the last value.

I am using another text variable formattedPicklistValues to store the formatted picklist values.

{!rawMultiSelectPicklistValues} +";"

The values in formattedPicklistValues looks like Agriculture;Banking;Finance;

If you noticed it right, the last value now has a semicolon appended.

Step 4:

What we are trying to do now is basically strip down or extract values one by one from the formattedPicklistValues variable. We will keep doing that until this string becomes null.

So, as a part of this step, we simply put a null check on this variable.

Step 5:

As we have 3 values from our example, we would now pick the first value using the formula formulaOnePicklistValue (TEXT) until our delimiter ; and straight away add it to our extractedPicklistValues (TEXT) collection.

TRIM( 
     LEFT(
              {!formattedPicklistValues} , 
              FIND(
                     ";",{!formattedPicklistValues}
             ) - 1
       ) 
 )

The value in the extractedPicklistValues collection would now be, [Agriculture]

Step 6:

Since we have successfully extracted the first value from our formattedPicklistValues variable and added it to our extractedPicklistValues collection in the previous step, it is now time to remove the first value from formattedPicklistValues itself.

And to do so, we would use another formula removeOnePicklistValue

TRIM(
     SUBSTITUTE({!formattedPicklistValues},  {!formulaOnePicklistValue}+";", "")
 )

The values in formattedPicklistValues will now be Banking;Finance;

And the flow will keep bouncing between Step 4, 5 and 6 until the formattedPicklistValues becomes null. And by this time, our extractedPicklistValues collection will have all the three values [Agriculture,Banking,Finance]

Step 7:

We would now Get all the Record Types for the Industry__c object and store it in industryRecordTypes collection.

Don’t forget to select the DeveloperName field. We really need that.

Step 8:

We will now have an outer loop over extractedPicklistValues collection.

Step 9:

We have to now loop over the RecordTypes object collection, industryRecordTypes.

Step 10:

This step is crucial as we would now be checking a match for the selected picklist values against the RecordType’s DeveloperName.

Step 11:

If there is a match, we will construct our industryRecord variable like below.

Step 12:

Now simply add this industryRecord to its list/collection so we can directly create records in one go.

Step 13:

Does it now work? Yes, it does.

I chose these values and clicked save.

Voila!

There are now 3 Industry__c records with correct record types driven by the chosen picklist values.

I hope this helps. 🙂

7 Comments

  1. i am getting an error in flow because i have no record types in my custom object, how can i create them and use jn this flow

  2. Hi, it looks great but what to do when my record type developer name doesn’t match the picklist label?
    Eg. My record type developer name is AssessmentKYCExternalRecordType whereas the picklist is KYC External

    • You could do some adjustments to the flow according to your setup. Example, you could use a formula variable with SUBSTITUTE function in it and remove spaces between “KYC External” so that it looks like “KYCExternal”

      Later you can check if the record type developer name contains “KYCExternal”

  3. Hi, thanks for this post! However, when the multiselect picklist options contain the same text, the parsing formulas don’t work. For instance, if one selects “Ohio; Central Ohio; Northern Ohio,” The word “Ohio” is removed from all three values and the flow ends up looping until it fails. Any suggestions that would enforce an exact match? Thanks.

Leave a Reply to mannuCancel reply

Discover more from Salesforce Binge

Subscribe now to keep reading and get access to the full archive.

Continue reading