How to run Step Group from the Flow


Breezz Framework lets you execute multiple Step Groups and their Steps inside of flow. Create a group just like before.

ToUpperCase Step Modification ToUpperCase Step Modification

And add Step to the newly created group. Let’s make some small changes in our Step Class which we created in Create Step class step.

 1// class need to extends forvendi.Step class
 2public with sharing class UpdateToUppercaseFieldStep extends forvendi.Step {
 3   
 4    public UpdateToUppercaseFieldStep() {
 5        super(UpdateToUppercaseFieldStep.class.getName());
 6    }
 7 
 8    public override Boolean initRecordProcessing(Object record, Object optionalOldRecord) {
 9        SObject sfRecord = (SObject)record;
10        String recordName = (String)sfRecord.get('Name');
11       
12        // using Modification Context to save changes in the database
13        getContext().addModificationToUpdate(
14             sfRecord.Id,
15             Account.Name,
16             String.isBlank(recordName) ? '' :  recordName.trim().toUpperCase().replace('  ', '_'));
17        // returning false - because we have all what we need to finish the process
18        return false;
19    }
20}

Configure New Step with Modification Configure New Step with Modification

As you see changes are quite cosmetic, instead of changing Account records directly we are using Modification Context to save our changes in the Salesforce Database. The addModificationToUpdate method is not executing DML operations so is safe for record level logic. Now that we modified Step and a group containing it is also set up, we need to create a flow to accommodate those changes. Create Autolaunched Flow.


Set of IDs

Firstly let’s create two variables.SetOfIds - Text Collection Variable and Account - Record Variable.

Set of IDs Variables Set of IDs Variables

Now create an Assignment Block and give your Account a name, just like before using lowercase letters. Next up is creating this new record and assigning it’s Id to our text collection variable as we will need it later on. Now onto the Breezz part, we will be using an example @invocablemethod called forvendi__InvocableStepFunctions which takes up two arguments. First we have already created - a set of record Ids and second is the DeveleperName of the Step Group we want to execute.

So create a Get Records Block and get a single record of Breezz Steps Group Config object, filter result to a record with DeveloperName of the group you want to execute. For our case it’s UpdateToUppercaseFieldSteps. Now that everything is prepared add Apex Action with the method we talked about before which is forvendi__InvocableStepFunctions, pass both SetOfIds and Step Group Config from Get Records.

Flow Graph Flow Graph

Save it and press run. The result should be an Account Record modified by actions from our Step Group.

Result Result


List of SObject

Another example of executing Step Group from flow is providing it with a list of SObjects. As almost everything in Breezz can be customized we won’t get into anything specific for now. We will reuse the group from before. Create another Autolaunched Flow. Start with creating a variable ListOfAccounts.

New Variable ListOfAccount New Variable ListOfAccount

Remember to make it so it is Available for input. Now add Create Records action and pick multiple record creation for our new resource. Just like previously add Apex Action but now pick Run Step Group for provided records. Enter Object for input and output which in both cases is Account. As input value pick our Record Collection variable ListOfAccount and Step Group which is UpdateToUppercaseFieldSteps.

Create Records Action Create Records Action

Flow should look something like this:

Autolaunched Flow Graph Autolaunched Flow Graph

After all this is done save, set a name and activate your flow. Now use the snippet below to execute and test out your flow. Change value of ‘FlowLaunch’ parameter to API Name of your flow.

 1// create a map of values that will be passed to the flow
 2    // string value is api name of variable inside flow that will take
 3    // object value passed with it
 4    Map<String,Object> params = new Map<String,Object>();
 5    List<Account> la = new List<Account>();
 6
 7
 8    // generate few example accounts and add them to the list
 9    for(Integer i = 0 ; i < 5 ; i++){
10    Account c = new Account(Name = 'Tst Acc ' + i*i+1 );
11    la.add(c);
12    }
13
14
15    // we put inside the map our list under the flow variable name 'ListOfAccounts'
16    // remember to change parameter 'FlowLaunch' for api name of your Flow
17    // and launch the flow
18    params.put('ListOfAccounts',la);
19    Flow.Interview myFlow = Flow.Interview.createInterview('FlowLaunch',params);
20        myFlow.start();

As a result you should see five new Account records generated, and if everything went well they should have uppercase value of the name field.