From Jeff Kranz: Use Collection Filter to Convert Selected Screen Choices to a Record Collection Without Apex

Jeff Kranz over at Riskonnect found a nifty way to utilize the new Collection Filter action to easily convert records selected in a screen choice to a record collection without any Apex. Check out what he sent over!

Screen Choices and their corresponding Choice Sets have come a long way over the years, but there are still some stumbling blocks when it comes to using them for real-world use cases. One of these remaining challenges is extracting the selected values of a multi-select Screen Choice component. Instead of a collection that you can easily process in a loop or send to an apex action, it gives you semi-colon separated text of the selected values. Over the years, there have been some clever workarounds, and some helpful apex actions from the community, but now with enhancements from Spring 22, we can “convert” those selections to a record collection without an Apex Action and more efficiently than previous workarounds.

First, lets set up an overly-simplified, admittedly-contrived scenario.

As a Sales User,
I want to view and select one or more Contacts related to an Account,
So that I can [do something valuable- remind them of an upcoming event?].

There are always several ways to skin a cat in Salesforce, so lets not get hung up on alternative features for this use case, but rather the general idea of using record collections to let a user make a multi-select choice and then operate on those selected records.

Let’s Build!

The basic idea is straightforward. Here are the pieces:

  1. Build a collection of records for user selection (through a Get or otherwise)
  2. A screen that presents the user with those records as choices.
  3. Filter the record collection to to just the records that the user selected.
  4. Profit!

Build a collection of records for user selection

In the past, you may have reached for a Record Choice Set to fill out those choices. You can still do that, but for our solution to work, we’ll still need a collection separate from the choice to work with, so we’ll use the new Record Collection Choice Set feature by placing a Get element before the Screen to retrieve the related Contacts and use that as the source for a Record Collection Choice Set.

A screen that presents the user with those records as choices.

We’ll need at least one screen that has our Choice (we’ll use the Checkbox Group component), configured to use the Record Collection from that Get as the source for the Collection Choice Set.

Filter the record collection to to just the records that the user selected

Here’s the fun part. When the user reaches that screen, they should see something like what you see on the right here, allowing them to select multiple choices.

If you’ve configured multi-select choices, you’ll know that when you reference these selected values later in the Flow, you’ll get something like “XYZ0000000001AAA;XYZ0000000002AAA”. That is, a semi-colon separated text value.

Ok. Thank you. But… not very useful.

Let’s turn that into a collection! But first, we have to do a little workaround to make those selected choice values play nicely in our Filter formula.

“Assign Choices to Text Variable” Workaround

After the screen, but before the new Filter we’ll be adding, place an Assignment element, and assign the Checkbox Group Screen Component reference (which stores the semi-colon separate values) to a text variable. I won’t go into detail over why you must do this – mostly because I don’t know for sure – but you do need to do it, and I suspect it has to do with the way that choice values can sometimes return the label instead of the value for its value. Nevertheless- this one simple trick will help our next step work.

Filter to “Convert” Original Collection to Selected Records

Now, we can go ahead and create that Filter to give us just the records that were selected in the Screen Choice. The filter should be configured to use a formula, and that formula should use the CONTAINS() function to match only the records that are one of the selected values (using your text variable assigned in the previous step) against the ID value for each item in the collection you are filtering.


Verify Our Expectations with Debug Before We Build Out Further

Before we even move forward with trying to build out more processing on the collection we are now expecting, we can use the Debug mode to Confirm that it is working the way we think it should.
If run Debug for an Account record that has Contacts, and select a couple of them, we can see that we’ve now got a record collection of those Contacts available to us for processing in a Loop:


In this post we learned how to turn the selected values from a Screen Choice into a Record Collection of those choices that you can use to operate on in the Flow without any custom apex or third party packages.

You might conclude that it is still some additional overhead, and I might agree. If you can, a custom screen component like UnofficialSF’s DataTable, or this DataTable component, can provide a much more robust, concise Flow configuration for a situation like this. But many of us find ourselves needing to work within the bounds of what tools we get out-of-the-box, and this new approach we can take to converting selected choices into an actionable collection is much more concise and expressive than what we’ve been able to do previously, and I highly recommend considering this approach when you’ve got this kind of restriction and a use case with this kind of need. Happy Flow Building!

Learn more