Generate Element

The Generate step is introduced in Summer ’19 to allow you to dynamically generate Recommendations. Say you want to offer certain products to a customer in certain circumstances. If you have 3 different products to offer, creating Recommendations for each of them is fine. But what if there are 50, or 100, or 10.000? Then creating Recommendations for each of them is going a lot of work. This is where the Generate comes in handy.

The Generate step relies on an Apex class to do the heavy lifting of actually generating the recommendations. You can define one or more inputs for the generation process and the Apex class always needs to return a list of recommendations (well actually the Apex class should support bulkification, so it should actually expect a list of input parameters and return a list of list of recommendations.

An example of an Apex class could look like this:

global class NBAGenerateTemplate {
        @InvocableMethod(
        label='NBA Generate Example'
        description='This function returns some random recommendations as an example')
        global static List<List<Recommendation>> sampleMethod(List<NBAGenerateTemplateRequest> inputRequests) {
        List<List<Recommendation>> outputs = new List<List<Recommendation>>();

        for (NBAGenerateTemplateRequest inputRequest : inputRequests)
        {
            List<Recommendation> singleRequestOutputs = new List<Recommendations>();
            
            Recommendation NewRecommendation1 = new Recommendation();
            
            NewRecommendation1.Name = 'Sample recommendation 1 for ' + inputRequest.FirstInputVariable + ' ' + inputRequest.SecondInputVariable;
            NewRecommendation1.Description = 'Sample recommendation 1 for ' + inputRequest.FirstInputVariable + ' ' + inputRequest.SecondInputVariable;
            NewRecommendation1.AcceptanceLabel = 'Yes';
            NewRecommendation1.RejectionLabel = 'No';
            NewRecommendation1.ActionReference = 'NBA_101_Example_Flow';
            
            singleRequestOutputs.add(NewRecommendation1);
            
            Recommendation NewRecommendation2 = new Recommendation();
            
            NewRecommendation2.Name = 'Sample recommendation 2 for ' + inputRequest.FirstInputVariable + ' ' + inputRequest.SecondInputVariable;
            NewRecommendation2.Description = 'Sample recommendation 2 for ' + inputRequest.FirstInputVariable + ' ' + inputRequest.SecondInputVariable;
            NewRecommendation2.AcceptanceLabel = 'Yes';
            NewRecommendation2.RejectionLabel = 'No';
            NewRecommendation2.ActionReference = 'NBA_101_Example_Flow';
            
            singleRequestOutputs.add(NewRecommendation2);
            
            outputs.add(singleRequestOutputs);
        }
        return outputs;
    }
    
    global class NBAGenerateTemplateRequest {
        @InvocableVariable
        global String FirstInputVariable;
         
        @InvocableVariable
        global String SecondInputVariable;
    }
}

Things to note on this Apex class are:

  • It uses an inner class NBAGenerateTemplateRequest for defining the input parameters.
  • Each parameter needs to have the @InvocableVariable defined
  • The class has one method with the @InvocableMethod defined
  • That method receives a List of NBAGenerateTemplateRequest as input argument
  • The method returns a List of List of Recommendations
  • In this example it returns 2 recommendations for each input and the input variables are concatenated in the Description of the Recommendation

Now when we add the Generate step to our strategy, it looks like this:

Generate Screenshot

We see that the Apex function ‘NBA Generate Example’ is chosen (that is the Label of the method of the class) and we see that the two Input arguments FirstInputVariable and SecondInputVariable are listed. We used the $Record and $User variables to set the values for the Generate input arguments.

The resulting strategy then looks like:

Generate Screenshot

And the result on the Case detail page is:

Generate Screenshot

We see that the first two recommendations are the result of the Generate step and that the input parameters have been used in the description of the recommendation.

Back to Elements

2249 reads