Invoke Apex Actions from Flow | Salesforce Flow Guide : rajesh andani

Invoke Apex Actions from Flow | Salesforce Flow Guide
by: rajesh andani
blow post content copied from  Forcetalks
click here to view original post

Salesforce took editing to the next level by launching Flows, allowing users to prepare for a complex flow in a matter of minutes. However, comfort comes with its own setbacks as there are some limitations to what Flow can do. 

For example, if your flow uses closed loops, duplicating more than 2000 elements or making more than 100 queries will exceed the

 The recommended solution for creating a complex mindset is to use Apex and the good news is, that you can still use Flows and extract the most complex function from Apex using Apex Actions. 

In this article, I will be illustrating a case in point, where the requirement is to create interactive records within a large collection of records. 

Assume we have custom items representing Student, Class and they have many to many relationships. I will use the Flow and Apex action to duplicate a set of records and create meeting records (Registration). The use case creates registration records for a particular semester when students make corresponding payments. 

This requirement requires a fixed loop or multiple queries to obtain the same records and compile the required maps between enrolled students, payments and classes. This can easily exceed the flow limits. But we can transfer excessive processing to Apex and get the result. 

dont miss out iconDon't forget to check out: Apex Basics and Database | Salesforce Apex Tutorial Guide


The flow we will use is as follows. Note that this is an MVP and the real situation can be complicated. 

We will use ‘Access to Records’ materials to collect Student, Class and Payment records. Then the idea is to transfer to Apex action and restore the list of subscription records. Then use ‘Create Objects’ to create records. 

Let's take a look at the Apex code that will be used before digging deep into the Flow element. 

Code template 

The template for Apex Code (Apex section without any logic processing) is as follows. 

Selected method: 

The requested method is a method called Apex Action in the Flow. 

  1. The invoked method:

The @InvocableMethod annotation allows Flow to drive the route 

Use the 'label' attribute to define the Apex Action display name 

It may contain only one parameter 

You can have only one non-verbal approach in each class 

  1. Input parameters:

Although the default method may have only one parameter, you can use the custom types to define multiple features, and then use that custom type as the input parameter.

The @InvocableVariable annotation allows Flow to set variables 

If the custom type is used as the input parameter, it should be 'List' 

dont miss out iconCheck out another amazing blog by Rajesh here: Relationships in Salesforce Financial Services Cloud

  1. Output parameters:

Similar to the input parameters, the output parameters can also be defined using the custom type, where you can define multiple elements. 

The @InvocableVariable annotation allows Flow to access the output variable 

If the custom type is used as the output parameter, it should be 'List' 

Apex Action in the Flow

If you already have the Apex code in place, you can add the Apex Action Flow feature to your trip. You can see that the "label" we defined in our Apex class is the word displayed in Apex Action. When you add Apex Action, you can define input and output as you like.

The post Invoke Apex Actions from Flow | Salesforce Flow Guide appeared first on Forcetalks.

June 04, 2022 at 12:30AM
Click here for more details...

The original post is available in Forcetalks by rajesh andani
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.