Skip to main content
Scheduled Maintenance: Trailhead, myTrailhead, and Trailblazer Community will be offline January 17, 16:00–20:00 UTC. Thanks for bearing with us as we update your experience!

Create a Flow with a Multi-Select Picklist

Learning Objectives

In this badge, you'll:

  • Build a screen flow that contains a multi-select picklist component.
  • Create an Assignment element that stores the selections as a string in a text variable.
  • Use a Decision element and the Connect to Element function to form a manual loop.
  • Create formulas and Assignment elements that manage the selections and copy them to a text collection, one at a time.
  • Transform the text collection's selections into a record collection variable.
Note

This badge is one stop along the way to Flow Builder proficiency. From start to finish, the Build Flows with Flow Builder trail guides you through learning all about Flow Builder. Follow this recommended sequence of badges to build strong process automation skills and become a Flow Builder expert.

Work with Multi-Select Choice Sets

In Flow Builder, you create a manual loop when you use the Connect to Element function to manually connect an element on a Decision’s path back to that Decision element, forming a looping path. The path doesn’t visually form a loop, but the Go To Connector that was created by the Connect to Element function points the flow’s path back to a previous element.

On the Flow Builder canvas, a Go To Connector points from one of a Decision element’s paths back to the Decision element that created the path.

As stated in the Loops in Flow Builder badge, you should create a manual loop in a flow only when necessary. Unfortunately, the Checkbox Group, Choice Lookup, and Multi-select Picklist components, which work well with choice sets, are incompatible with Transform and Loop elements. When you use a Checkbox Group, Choice Lookup, or Multi-Select Picklist to capture multiple choices, you must process the chosen options by looping through them manually. But Loop elements can't loop through screen component selections, so how do you loop through those selections?

When working with multiple points of similar data, flows work best if that data is in one collection variable. However, those components store their data in a single text string that looks like this: 001B000000Qu2XxIAJ;001B000000Qu2XyIAJ;001B000000Qu2XzIAJ;001B000000Qu2Y0IAJ

The selections are stored as a text string of record IDs, separated by semicolons. Salesforce considers this kind of data to be unstructured data: a series of text values stored together with no system-controlled separation. The semicolons separating the IDs provide some structure, but these semicolons can be moved or removed, so Salesforce doesn’t recognize them as definitive structure.

In contrast, collection variables are structured data, made of individual values separated by the variable. This separation is important, because it tells the flow with absolute certainty where one value ends and the next value begins.

Certain elements’ configuration, such as the Get Records element, accept only structured data—a collection variable. So if you need to use choice set selections in one of these structured-data-only elements, you must convert the unstructured data into the structured data of a collection variable. Sometimes you just need to turn a semicolon-delimited string of IDs into a text collection variable, but other times, you might also need to turn that new text collection variable into a record collection variable.

Break a Long String of Values into Many Smaller Values

To process multiple selections from a choice set-based screen component, create a flow that:

  1. Gathers selections on a screen.
  2. Uses Assignment elements and formulas to copy the first selection into a text collection variable.
  3. Uses a Decision element and the Connect to Element function to loop back and do step 2 again, repeating as needed until all selections have been copied to the text collection variable.
  4. Uses a Get Records element to retrieve all the records whose IDs are in the text collection variable and store them in a record collection variable.
  5. Does whatever you need to do with that record collection variable.

There's a lot of magic buried in step 2, but don't worry, we'll break that step down further.

Note

In this badge, you learn one way of converting selections into a collection variable. The wonderful and resourceful members of the Trailhead community have published many different methods all around the internet. This method should work for most cases, but if this method doesn’t click for you, feel free to search for other methods. Also, the variable and formula names presented here are designed for clarity as you learn, but feel free to make up your own.

Create a New Trailhead Playground

For this hands-on badge, you need to create a new Trailhead Playground. Scroll to the bottom of this page, click the playground name, then click Create Playground. It typically takes 3–4 minutes to create a new Trailhead Playground.

Note: Yes, we really mean a brand-new Trailhead playground! If you use an existing org or playground, you can run into problems completing this badge.

Create a Screen Flow

In this badge, you help the marketing team at Pyroclastic, Inc. to create a flow. They want to add all of an account’s contacts to a campaign, and they want to do it for multiple accounts. Create a flow that runs from a campaign record page, asks users to select accounts, converts those selections into a text collection, retrieves all the contacts related to the chosen accounts, and adds them to the current campaign as campaign members.

  1. Create a screen flow.
  2. Create a variable to store the current campaign’s ID.
    • For Resource Type, select Variable.
    • For API Name, enter varCampaignID.
    • For Data Type, select Text.
    • For Availability Outside the Flow, select Available for input.
    • Click Done.
  3. Create a Screen element that asks the user to choose accounts.
    • For Label, enter Select Accounts.
    • Make sure the API Name is Select_Accounts.
  4. Add a Multi-Select Picklist component to the screen canvas.
    • For Label, enter Select accounts - all related contacts will be added to this campaign.
    • Make sure the API Name is Select_accounts_all_related_contacts_will_be_added_to_this_campaign.
    • For Let Users Select Multiple Options, make sure Yes is selected.
    • For Choice, select New Choice Resource.
      • For Resource Type, select Record Choice Set.
      • For API Name, enter AccountChoice.
      • For Object, select Account.
      • For Condition Requirements, select None—Get All Account Records.
      • For Sort Order, select Ascending.
      • For Sort By, select Name.
      • For Choice Label, select Name.
      • For Choice Value, select Id.
      • Click Done to close the New Choice Resource window.
    • Click Done to close the screen canvas.
  5. Save the flow.
    • For Flow Label, enter Create Campaign Members from Selected Accounts.
    • Make sure the Flow API Name is Create_Campaign_Members_from_Selected_Accounts.
Share your Trailhead feedback over on Salesforce Help.

We'd love to hear about your experience with Trailhead - you can now access the new feedback form anytime from the Salesforce Help site.

Learn More Continue to Share Feedback