Submit For Review

Generate Element

Title Changes:

Generate ElementGenerate Element

Content Changes:

Removed Added
Unchanged: <p>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.</p><p>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.</p><p>An example of an Apex class could look like this:</p><pre>global class NBAGenerateTemplate {Unchanged: <p>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.</p><p>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.</p><p>An example of an Apex class could look like this:</p><pre>global class NBAGenerateTemplate {
Unchanged: @InvocableMethod(Unchanged: @InvocableMethod(
Unchanged: label='NBA Generate Example'Unchanged: label='NBA Generate Example'
Unchanged: description='This function returns some random recommendations as an example')Unchanged: description='This function returns some random recommendations as an example')
Unchanged: global static List&lt;List&lt;Recommendation&gt;&gt; sampleMethod(List&lt;NBAGenerateTemplateRequest&gt; inputRequests) {Unchanged: global static List&lt;List&lt;Recommendation&gt;&gt; sampleMethod(List&lt;NBAGenerateTemplateRequest&gt; inputRequests) {
Unchanged: List&lt;List&lt;Recommendation&gt;&gt; outputs = new List&lt;List&lt;Recommendation&gt;&gt;();Unchanged: List&lt;List&lt;Recommendation&gt;&gt; outputs = new List&lt;List&lt;Recommendation&gt;&gt;();
Unchanged: for (NBAGenerateTemplateRequest inputRequest : inputRequests)Unchanged: for (NBAGenerateTemplateRequest inputRequest : inputRequests)
Unchanged: {Unchanged: {
Unchanged: List&lt;Recommendation&gt; singleRequestOutputs = new List&lt;Recommendations&gt;();Unchanged: List&lt;Recommendation&gt; singleRequestOutputs = new List&lt;Recommendations&gt;();
Unchanged: Unchanged:
Unchanged: Recommendation NewRecommendation1 = new Recommendation();Unchanged: Recommendation NewRecommendation1 = new Recommendation();
Unchanged: Unchanged:
Unchanged: NewRecommendation1.Name = 'Sample recommendation 1 for ' + inputRequest.FirstInputVariable + ' ' + inputRequest.SecondInputVariable;Unchanged: NewRecommendation1.Name = 'Sample recommendation 1 for ' + inputRequest.FirstInputVariable + ' ' + inputRequest.SecondInputVariable;
Unchanged: NewRecommendation1.Description = 'Sample recommendation 1 for ' + inputRequest.FirstInputVariable + ' ' + inputRequest.SecondInputVariable;Unchanged: NewRecommendation1.Description = 'Sample recommendation 1 for ' + inputRequest.FirstInputVariable + ' ' + inputRequest.SecondInputVariable;
Unchanged: NewRecommendation1.AcceptanceLabel = 'Yes';Unchanged: NewRecommendation1.AcceptanceLabel = 'Yes';
Unchanged: NewRecommendation1.RejectionLabel = 'No';Unchanged: NewRecommendation1.RejectionLabel = 'No';
Unchanged: NewRecommendation1.ActionReference = 'NBA_101_Example_Flow';Unchanged: NewRecommendation1.ActionReference = 'NBA_101_Example_Flow';
Unchanged: Unchanged:
Unchanged: singleRequestOutputs.add(NewRecommendation1);Unchanged: singleRequestOutputs.add(NewRecommendation1);
Unchanged: Unchanged:
Unchanged: Recommendation NewRecommendation2 = new Recommendation();Unchanged: Recommendation NewRecommendation2 = new Recommendation();
Unchanged: Unchanged:
Unchanged: NewRecommendation2.Name = 'Sample recommendation 2 for ' + inputRequest.FirstInputVariable + ' ' + inputRequest.SecondInputVariable;Unchanged: NewRecommendation2.Name = 'Sample recommendation 2 for ' + inputRequest.FirstInputVariable + ' ' + inputRequest.SecondInputVariable;
Unchanged: NewRecommendation2.Description = 'Sample recommendation 2 for ' + inputRequest.FirstInputVariable + ' ' + inputRequest.SecondInputVariable;Unchanged: NewRecommendation2.Description = 'Sample recommendation 2 for ' + inputRequest.FirstInputVariable + ' ' + inputRequest.SecondInputVariable;
Unchanged: NewRecommendation2.AcceptanceLabel = 'Yes';Unchanged: NewRecommendation2.AcceptanceLabel = 'Yes';
Unchanged: NewRecommendation2.RejectionLabel = 'No';Unchanged: NewRecommendation2.RejectionLabel = 'No';
Unchanged: NewRecommendation2.ActionReference = 'NBA_101_Example_Flow';Unchanged: NewRecommendation2.ActionReference = 'NBA_101_Example_Flow';
Unchanged: Unchanged:
Unchanged: singleRequestOutputs.add(NewRecommendation2);Unchanged: singleRequestOutputs.add(NewRecommendation2);
Unchanged: Unchanged:
Unchanged: outputs.add(singleRequestOutputs);Unchanged: outputs.add(singleRequestOutputs);
Unchanged: }Unchanged: }
Unchanged: return outputs;Unchanged: return outputs;
Unchanged: }Unchanged: }
Unchanged: Unchanged:
Unchanged: global class NBAGenerateTemplateRequest {Unchanged: global class NBAGenerateTemplateRequest {
Unchanged: @InvocableVariableUnchanged: @InvocableVariable
Unchanged: global String FirstInputVariable;Unchanged: global String FirstInputVariable;
Unchanged: Unchanged:
Unchanged: @InvocableVariableUnchanged: @InvocableVariable
Unchanged: global String SecondInputVariable;Unchanged: global String SecondInputVariable;
Unchanged: }Unchanged: }
Unchanged: }Unchanged: }
Deleted: </pre><p>Things to note on this Apex class are:</p><ul><li>It uses an inner class NBAGenerateTemplateRequest for defining the input parameters.</li><li>Each parameter needs to have the @InvocableVariable defined</li><li>The class has one method with the @InvocableMethod defined</li><li>That method receives a List of NBAGenerateTemplateRequest as input argument</li><li>The method returns a List of List of Recommendations</li><li>In this example it returns 2 recommendations for each input and the input variables are concatenated in the Description of the Recommendation</li></ul><p>Now when we add the Generate step to our strategy, it looks like this:</p><p><img src="https://i0.wp.com/www.jackvandijk.nl/NBA/NBA101/generatescreenshot1.png?zoom=1.7999999523162842&amp;w=1500&amp;ssl=1" alt="Generate Screenshot" width="938" height="618" data-recalc-dims="1" /></p><p>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.</p><p>The resulting strategy then looks like:</p><p><img src="https://i1.wp.com/www.jackvandijk.nl/NBA/NBA101/generatescreenshot2.png?zoom=1.7999999523162842&amp;w=1500&amp;ssl=1" alt="Generate Screenshot" width="605" height="351" data-recalc-dims="1" /></p><p>And the result on the Case detail page is:</p><p><img src="https://i0.wp.com/www.jackvandijk.nl/NBA/NBA101/generatescreenshot3.png?zoom=1.7999999523162842&amp;w=1500&amp;ssl=1" alt="Generate Screenshot" width="400" height="693" data-recalc-dims="1" /></p><p>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.</p> Added: </pre><p>Things to note on this Apex class are:</p><ul><li>It uses an inner class NBAGenerateTemplateRequest for defining the input parameters.</li><li>Each parameter needs to have the @InvocableVariable defined</li><li>The class has one method with the @InvocableMethod defined</li><li>That method receives a List of NBAGenerateTemplateRequest as input argument</li><li>The method returns a List of List of Recommendations</li><li>In this example it returns 2 recommendations for each input and the input variables are concatenated in the Description of the Recommendation</li></ul><p>Now when we add the Generate step to our strategy, it looks like this:</p><p><img src="https://i0.wp.com/www.jackvandijk.nl/NBA/NBA101/generatescreenshot1.png?zoom=1.7999999523162842&amp;w=1500&amp;ssl=1" alt="Generate Screenshot" width="938" height="618" data-recalc-dims="1" /></p><p>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.</p><p>The resulting strategy then looks like:</p><p><img src="https://i1.wp.com/www.jackvandijk.nl/NBA/NBA101/generatescreenshot2.png?zoom=1.7999999523162842&amp;w=1500&amp;ssl=1" alt="Generate Screenshot" width="605" height="351" data-recalc-dims="1" /></p><p>And the result on the Case detail page is:</p><p><img src="https://i0.wp.com/www.jackvandijk.nl/NBA/NBA101/generatescreenshot3.png?zoom=1.7999999523162842&amp;w=1500&amp;ssl=1" alt="Generate Screenshot" width="400" height="693" data-recalc-dims="1" /></p><p>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.</p><p><a href="https://unofficialsf.com/the-salesforce-automation-and-decisioning-wiki/elements-3/">Back to Elements</a></p>