Flows | Loop on Checkbox Group Values in Flow using Apex Action

Salesforce Flow Get Values from Checkbox Group. In this post we will see how to Parse and use the values from a Multi Select Checkbox Group on a Screen Flow. Salesforce Flow Multi Select Checkbox can used for many use cases. We will use a Record Choice Set to show Multiple Checkboxes on Flow Screen and display Record values as choices or checkboxes. After that we will explore a way to use the selected values from the Record Choice Set to perform actions like Looping over the Checkbox Group values.  Let's see how to use the Salesforce Flow Checkbox Group Output effectively. 

The best part is all you need is a Re-Useable and downloadable Apex Action to Parse Multi select  CheckBox Group Values. 

Loop on Checkbox Group Values in Flow

Why we need to Parse Checkbox Group Choice values in Flow?

When we use a Checkbox Group on a Screen Flow, we are not able to use the user Selected values in Loops or Update Elements. This becomes an issue in many use cases where you need to Loop on Selected Values from a Check Box Group in Screen Flows. 

Whenever we use a Checkbox Group choice set on a Flow Screen, the format of the selected values is like this [A;B;C;D] which is a semi-colon separated  String Variable and not a Collection Variable. This kind of variable is not considered as a Flow Collection Variable and cannot be used as a Flow Loop Variable. We somehow need to convert the format of these selected values to [A,B,C,D] similar to a Text collection variable so that it can be used in Loops to Loop on CheckBox Group Selected Choices or Values in a Flow.

How to use the values of Choice from CheckBox Group in Flow?

We will just use an Apex Action which can be downloaded and used to use the values. 
Checkout this Article where I have shown the same functionality but instead used Multi Select Picklist values to use in Loops Use Multi Select Picklist Values in Loops and Other Operations . Exact same Apex Action can be used in similar way for Checkbox Group in Screen Flows.



Download the Un-Managed Package from Links Below



Note : In case Package throws issues while Installation, below is the basic code that can be copy pasted in the org and can be used instead of the package.

Apex Class


global class MultiSelectFlowValues {

   

   @InvocableMethod

   public static List<list<string>> CheckValues(List<string> values) {

      if(!(values.isEmpty())){

          

          string tempStr = values[0];

          List<String> lstnew = tempStr.split(';');

          list<list<string>> finalLst = new list<list<string>>();

          finalLst.add(lstnew);

          return finalLst;

      }

      else return null;

   }

}


Test Class


@isTest

public class MultiSelectFlowValuesTestClass{

    

    @isTest

    static void MultiSelectFlowValuesTest(){

    

        List<string> tempLst = new list<string>();

        tempLst.add('AccidentalCoder');

        tempLst.add('Salesforce');

        MultiselectFlowvalues.CheckValues(tempLst);


    }

}



Learn Salesforce Development from Scratch


Steps to Use this Package/Component :

1. Install the Package (for all Users) from link above (This step not needed if you copy the code instead)
2. On the Flow Canvas, Go to Action Element and Drag it on the Flow Canvas.
3. Search for Multi Select Flow from Search Box in the Action Element.
4. Select the option MultiSelectFlowValues which is the name of the Apex Class. Once Package is downloaded this will be visible otherwise you wont see this option.
5. Provide a name of the Element. 
6. Click on the Toggle Bar to include Input Values in the Action Element Screen.
7In the Input value box just pass the Screen variable name which has Checkbox Group Values and need to be converted into a collection variable. 
8. That's it. 

Important : Now this Flow action Element will behave like a Text Collection Variable and can be used anywhere inside the Flow. The name of this collection variable will be the name/label of the Action Element that you provided in step 5 above. Checkout how that works in this article later.

Loop on Selected Values of a Checkbox Group in a Flow

When you use this Apex Component and Pass selected Record Choice Values or checkbox groups values to it, it converts those selected values into a Collection String variable which can be used to Loop on selected values of the Record Choice or Checkbox group.

Let's see this with a simple example below in a Video.

Now when a User will select some values from this screen, we will use the Action to get a String Collection Variable of these values which can be used for Looping on these selected Records.

There are many more use cases but I am sample Use Cases to Loop over some Selected Records from a Checkbox Group. Below Video shows a sample Use Case where we will show some Case records on the Flow Screen using Checkbox Group.

Checkout this Article where I have shown the same functionality but have Parsed on Multi Select Picklist values to use in Loops Use Multi Select Picklist Values in Loops and Other Operations . 

BEST ONLINE SALESFORCE COURSES - START LEARNING TODAY!
If you like reading my content, Subscribe to my Upcoming YOUTUBE Channel here: https://www.youtube.com/channel/UCdfi8Sq7iOcxnFhsgulWHeg/videos?view=0&sort=p&flow=grid

Don't Miss Latest Posts :  CLICK HERE TO SUBSCRIBE TO THIS BLOG

Checkout All Flow Examples on this Blog: All Flow Examples

Get Sharing and Visibility Designer Certification

Learn Flows Online

Comments

POPULAR POSTS

Salesforce Flow Examples : Flow Use Cases and Scenarios

Salesforce Spring '21 Release Preview | Latest Flow Features


Never Miss Latest Posts