Hurray! Parsing a Multi-Select Picklist is Trouble No More! Phew!

Hurray! Parsing a Multi-Select Picklist is Trouble No More! Phew!

Big Idea or Enduring Question:

Provide a wizard that allows your Inside Sales Team, Telemarketers to add Lead to multiple Campaigns.

6 years ago I wrote an article (Add Record to Multiple Chatter Groups – Parsing Multi-Select Picklist fields) to parse Multi-Select Picklist or Checkbox Group in Salesforce Flow. Not surprisingly, this has been one of the most read blogs on Automation Champion – for good reasons! 

Often, readers of my blog ask – is there an easier and quicker way to parse Multi-Select Picklist in Flow without Apex? In their question, I could almost ‘hear’ my readers chide me – ‘are you not able to figure out a better, easier, quicker way to parse Multi-Select Picklist in Flow without Apex? 🤔  Well, I could disappoint no more! So, here I go!

But, before going ahead let’s spend a few minutes to understand what is needed to parse Multi-Select Picklist or Checkbox Group?

The answer is very simple, if you select three campaigns (as shown in the preceding screenshot) Salesforce will save the record ids in a comma separated format NOT in a Collection Variable. Applicable for both Checkbox Group and Multi-Select Picklist. 

701B0000000UKG1;701B0000000HRFi;701B0000000UKG1

Now, if you want to use a specific campaign in a Flow then, your only option is to parse the Ids. Don’t worry – parsing is very easy and quick. I promise it will take less time than cooking noodles!!

Objectives:

This blog post will help us to understand the following:

  • How to parse a Multi-select Picklist
  • How to parse a Checkbox Group
  • How to use a formula in Salesforce Flow to optimize it 
  • How to execute a Decision element multiple times
  • And, last but not least, discover how to use the Create Records element to create multiple records (add campaign members) all at once (Bulk Safe) – (hmmm… so many, hows!)

Business Use Case

Brenda David is working as a System Administrator at Universal Containers (UC). As part of the Lead Optimization process, she received following requirements from her Sales Director Chris Mattison. Their conversation went as follows:

  • Brenda, last week I met with a few telemarketers in our Dallas office. One of the common issues raised by the telemarketers was that whenever they called a Prospect/Lead they found that the Prospect/Lead were influenced by many of our campaigns. As a result, to better maintain attribution, telemarketers manually added the Prospect/Lead to multiple campaigns based on their conversation with the Prospects/Leads.
  • I need your help to make telemarketers’ lives easier! Is it possible to create a screen that the telemarketers can launch from a Lead record and select multiple campaigns? Once done then, the telemarketers should be able to add the Leads to campaign as members.

Automation Champion Approach (I-do):

There are a few possible solutions for the above business scenario but, I’ll use Screen Flow to solve the business requirement. The main reason to select screen flow as we want to allow users to provide an input. 

Before proceeding, let us take a few minutes to understand the CampaignMember object in Salesforce. The object represents association between a campaign and (1) either a Lead or, (2) a Contact.

Field Name Details
CampaignId The Id of the Campaign to which this Lead or Contact is associated.
LeadId The Id of the Lead who is associated with a Campaign.

Second, let us understand the
 MID formula. The formula returns a specified number of characters from the middle of a text string given the starting position.

Before discussing the solution, let me show you a diagram of a Process Flow at a high level. Please spend a few minutes going through the following Flow diagram and understand it.

Let’s begin building this automation process.

Guided Practice (We-do):

There are 2 steps to solve Brenda’s business requirement using Screen Flow. We must:
  1. Salesforce Flow Steps: Define flow properties
    1. Create a text variable to store selected campaign Ids
    2. Add a screen to capture the user’s input
      1. Add a Multi-Select Picklist component to display active Campaigns 
    3. Add an assignment element to add selected campaign Id into a text variable 
    4. Create a number variable to store Start Number 
    5. Add a formula resource to get one campaign at a time from the selected campaigns Ids
    6. Add a decision element to check if the formula returns a record Id
    7. Add an assignment element to populate campaign member record variable 
    8. Add an assignment element to add campaign member record variable into a record collection variable
      1. Increase the Start Number by 19  
        1. Wait a minute! you may wonder – why should I increase the Start Number by 19? Aren’t we using an 18 digit Salesforce Id?. 
        2. My response – great question!! Alway be vigilant when reading any blog! Question everything! Ask why!
          1. Ok, so, here is an explanation as to why we need to increase the Start Number by 19… a Record ID is 18 digits, true. Since we are using multiple ids, we need to separate the ids by using a ‘;’. So, we need to add a space for the ‘;’.!
    9. Add a Create Records element to add campaign members records 
  2. Create a Quick Action to Launch the Flow

Step 1: Salesforce Flow – Define Flow Properties   

  1. Click Setup.
  2. In the Quick Find box, type Flows.
  3. Select Flows then click on the New Flow.
  4. Select the Screen Flow option and click on Next and configure the flow as follows: 
    1. How do you want to start building: Freeform
  5. It will open the flow designer for you.

Step 1.1: Salesforce Flow – Create a Text Variable to Store Selected Campaign Ids

  1. Under Toolbox, select Manager, then click New Resource to store the selected campaign Ids
  2. Input the following information: 
    1. Resource Type: Variable
    2. API Name: varTSelectedCampaignId
    3. Data Type: Text
    4. Default Value: {!$GlobalConstant.EmptyString}
    5. Check Available for Input
    6. Check Available for Output
  3. Click Done.

Step 1.2: Salesforce Flow – Add a Screen Element  

  1. Under Toolbox, select Elements. Drag and drop Screen onto the canvas. 
  2. Input the following information:
    1. Enter Label the API Name will auto-populate.
  3. Click Done

Step 1.2.1: Salesforce Flow – Add a Multi-Select Picklist Component to Display Active Campaigns 

  1. Under Input section on Screen Element. Drag and drop the Multi-Select Picklist component onto the screen. 
  2. Input the following information:
    1. Enter a name in the Label field; the API Name will auto-populate.
    2. Select Checkbox
    3. Under Choice 
      1. Click + New Resource, it will open a pop-up for you
      2. Resource Type: Record Choice Set
      3. API Name: recChoiceCampaigns 
      4. Object: Campaign
      5. Filter Campaign Records
        1. Row 1:
          1. Field: IsActive
          2. Operator: Equals 
          3. Value: {!$GlobalConstant.True}
      6. Configure Each Choice
        1. Choice Label: Name
        2. Data Type: Text
        3. Choice Value: Id
      7. Click Done
  3. Click Done.

Step 1.3: Salesforce Flow – Adding an Assignment Element to Add Selected Campaign Ids into a Text Variable  

  1. Enter a name in the Label (Populate Variable with Campaigns Id) field – the API Name will auto-populate.
  2. Set Variable Values
    1. Row 1:
      1. Field: {!varSelectedCampaignId}
      2. Operator: Add
      3. Value: {!Select_Campaigns}
  3. Click Done.

Step 1.4: Salesforce Flow – Create a Number Variable to Store Start Number

  1. Under Toolbox, select Manager, then click New Resource to store start number 
  2. Input the following information: 
    1. Resource Type: Variable
    2. API Name: varStartNumber
    3. Data Type: Number
    4. Decimal Value: 0
    5. Default Value: 1
    6. Check Available for Input
    7. Check Available for Output
  3. Click Done.

Step 1.5: Salesforce Flow – Add a Formula to Get one Campaign Id at a Time From the Selected Campaigns Ids

  1. Under Toolbox, select Managerthen click New Resource to create a formula to return one campaign Id
  2. Input the following information
    1. Resource Type: Formula
    2. API Name: for18DigitCampaignId
    3. Data Type: Text
    4. Formula: MID( {!varSelectedCampaignId}, {!varStartNumber}, 18)
  3. Click Done.

Step 1.6: Salesforce Flow – Using Decision Element to Check if Formula has Returns a RecordId

Now we will use a Decision element to check, if the formula has returned a recordId. The following screenshot should help you in configuring the Decision element.

  1. Under Toolbox, select Element
  2. Drag-and-drop Decision element onto the Flow designer. 
  3. Enter a name in the Label (Returned RecordId) field; the API Name will auto-populate.
  4. Under Outcome Details, enter the Label (Start Loop) the API Name will auto-populate.
  5. Condition Requirements to Execute OutcomeAll Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!$for18DigitCampaignId}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.False}
  6. Click Done.

 

Step 1.7: Salesforce Flow – Add an assignment element to Populate Campaign Member Record variable 

  1. Create a Record Variable varRCampaignMember of type Campaign Member to add a campaign member to a lead.
  2. Add a Text variable to pass current lead’s record id.
  3. Drag-and-drop the Assignment element onto the Flow designer. 
  4. Enter a name in the Label (Construct EntitySubscription field – the API Name will auto-populate.
  5. Set Variable Values
    1. Row 1:
      1. Field: {!varREntitySubscription.ParentId}
      2. Operator: Equals
      3. Value: {!$Record.Id}
    2. Click Add Assignment 
    3. Row 2:
      1. Field: {!varREntitySubscription.SubscriberId}
      2. Operator: Equals
      3. Value: {!Loop_through_Preferences.Follower_Name__c}
  6. Click Done.

Step 1.8: Salesforce Flow – Adding Campaign Member Record Variable to a Record Collection Variable and Increase the Start Number by 19

  1. Create a Record Collection Variable varRCampaignMember of type Campaign Member to store record variable (created in step 1.7) for the bulk process.
  2. Drag-and-drop the Assignment element onto the Flow designer. 
  3. Enter a name in the Label (Increase Start Variable & Bulkification) field – the API Name will auto-populate.
  4. Set Variable Values
    1. Row 1:
      1. Field: {!varRCampaignMembers}
      2. Operator: Add
      3. Value: {!varRCampaignMember}
    2. Click Add Assignment 
    3. Row 2:
      1. Field: {!varStartNumber}
      2. Operator: Add
      3. Value: 19
  5. Click Done.

Step 1.9: Salesforce Flow – Add a Create Records Element to Add Campaign Members Records 

  1. Drag-and-drop the Create Records element onto the Flow designer. 
  2. Enter a name in the Label (Add Campaign Members) field- the API Name will auto-populate.
  3. For How Many Records to Create select Multiple.
  4. Map Record Collection: {!varRCampaignMembers}
  5. Click Done.

In the end, Brenda’s Flow will look like the following screenshot:

Once everything looks good, perform the steps below: 

  1. Click Save.
  2. Enter Flow Label the API Name will auto-populate.
  3. Click Show Advanced.
  4. How to Run the Flow: API Version for Running the Flow: 52
  5. API Version for Running the Flow: 52
  6. Interview Label: Parse Multi-Select Picklist {!$Flow.CurrentDateTime}
  7. Click Save


Almost there! Once everything looks good, click the Activate button.

Step 2: Create a Quick Action to Launch the Flow

The next step is to create a quick action (Add to Campaigns) on the Lead object to launch the Flow. Salesforce will automatically pass the Lead Id to the recordId variable.

  1. Click Setup.
  2. In the Object Manager, type Lead.
  3. Select Buttons, Links, and Action, then click New Action.
  4. Input the following information:
    1. Select Flow as Action Type.
    2. Select Parse Multi-Select Picklist as Flow.
    3. Enter Label (Add to Campaigns) the Name will auto-populate.
  5. Click Save.

Make sure to add the Quick action to the Lead Lightning Record Pages. 

Proof of Concept

Going forward, anyone can use this application to add a Lead to multiple campaigns!

  1. To Add a Lead to multiple campaigns, click on the quick action and follow instructions on the screen as shown in the video:

Formative Assessment:

I want to hear from you!  

What did you learn from this post, is it relevant to you, and how will you modify the concepts taught in the post for your own business processes?  

Make a post and tag me on Twitter @automationchamp using #AutomationChampionFlow.

Proofreader: - Munira Majmundar
Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!
Preferred Timing(required)

8 thoughts on “Hurray! Parsing a Multi-Select Picklist is Trouble No More! Phew!

  1. Wow This is amazing!! I was stuck at “Loop” element forever, but I didn’t know you could do it without the “loop”! Could you give me some more information about the MID? why do we need to use MID? I followed without understanding it perfectly. Thanks for the article!

  2. Hi Rakesh, Great article and exactly what I was looking for. Just one comment for the step by step description: you don’t mention the required loop element anywhere – or did I miss something? Would be great if you could update that article accordinlgy (and probably also add new screenshots with “auto-layout’ in flow switched on 🙂 ). Thanks heaps!

  3. Great Post, thanks for writing it. I believe that Step 1.8 should have the starting number having 20 added, not 19(per “Guided Practice”, step 8). Also the title for 1.4 should describe a number variable instead of a text variable.

  4. This is an excellent solution for a string of IDs, where the values are of a fixed length (IDs are always 18 characters in this example).

    What about when the selections are picklist values, provided from a Picklist Choice Set? They appear as text strings of varying length. We need a little more to support that.

    * New variable (number) “nLastSelectionStart”, default = 0

    * New formula (number) “forNextSelectionStart”, value:
    FIND(“;”, {!varSelectedCampaignId}, {!nLastSelectionStart}+1)

    * New formula (text) “forNextSelection”, value:
    MID({!varSelectedCampaignId}, {!nLastSelectionStart}+1, {!forNextSelectionStart}-{!nLastSelectionStart}-1)

    * Change element “Increase Start Variable…”: to assign {!nLastSelectionStart} = {!forNextSelectionStart}

    * From this, you can do lots inside the loop, such as:
    (a) create a text collection “colSelections”; use Add in an assignment: colSelections [Add] {!forNextSelection}
    (b) add a new record to a collection with forNextSelection as one of the field values

    For my use case, I want to create Cases based on a list of case categories. The user is given a multiselect list of case categories (from Case.Category picklist values) and I want to parse the selections, then create one case per selection. If the select three categories, I create three cases!

    1. Oops I need to correct my comment!

      The formula for forNextSelectionStart needs to ensure the value in non-zero (or we miss the last selection). Here’s the correct formula:

      IF( FIND(“;”, {!varSelectedCampaignId}, {!nLastSelectionStart}+1) = 0,
      LEN({!varSelectedCampaignId}) + 1,
      FIND(“;”, {!varSelectedCampaignId}, {!nLastSelectionStart}+1)
      )

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.