Calling Invocable Apex Class from Flow

Mukul Mahawariya
3 min readMay 24, 2021

Salesforce provides a lot of standard features which allow the creation of custom logic while inserting a record. They are Workflow, Process Builder, and flow.

These standard features help users to some extent but for more custom solutions they have to use Apex Triggers, classes, and more.

But it’s cumbersome to write logic from scratch.

So, the salesforce allowed users to call apex classes from Process builder and Flow as invocable apex which helps users to not work from scratch instead he can call invocable apex from a node either in process builder or flow.

Workflow does not support invocable apex.

Process Builders do not take response from invocable apex but the flows do.

I am going to explain how you can call invocable apex and get a response.

  1. Create a Flow

2. Add a screen to get the user input

I have added a Name component for user input.

Now create an Apex class with Process.Plugin interface

global class flowChat implements Process.Plugin {// The main method to be implemented. The Flow calls this at run Process.PluginResult invoke(Process.PluginRequest request) {// Get the user input from the flowString firstName = (String) request.inputParameters.get('firstName');String lastName = (String) request.inputParameters.get('lastName');// return to FlowMap<String,Object> result = new Map<String,Object>();result.put('firstName','name'); //outputresult.put('lastName','changes'); //outputreturn new Process.PluginResult(result);}// Returns the describe information for the interfaceglobal Process.PluginDescribeResult describe() {Process.PluginDescribeResult result = new Process.PluginDescribeResult();result.Name = 'invocableApexExample';result.Tag = 'invoke';result.inputParameters = newList<Process.PluginDescribeResult.InputParameter>{new Process.PluginDescribeResult.InputParameter('firstName',Process.PluginDescribeResult.ParameterType.STRING, true),new Process.PluginDescribeResult.InputParameter('lastName',Process.PluginDescribeResult.ParameterType.STRING, true)};result.outputParameters = newList<Process.PluginDescribeResult.OutputParameter>{new      Process.PluginDescribeResult.OutputParameter('firstName', Process.PluginDescribeResult.ParameterType.STRING),new Process.PluginDescribeResult.OutputParameter('lastName', Process.PluginDescribeResult.ParameterType.STRING)};return result;}}

Process.PluginDescribeResult : Show some information regarding the apex class when you search for it in Flow.

Process.PluginDescribeResult.InputParameter : Specify input parameters for the apex class.

Process.PluginDescribeResult.OutputParameter : Specify output parameters to send information to flow.

3. Now search for your class name under Action>Apex Action (Legacy)

4. Add input and output parameters details -

Add the output values to two variables like — firstNameApex and lastNameApex.

5. Add a screen component with display text to show the response from Apex -

Your flow should like this -

Let’s try -

In the next screen, you will see the output from apex -

Conclusion -

  • Salesforce provides lots of standard tools to create some custom functionality but comes with some limitations.
  • To overcome these limitations we need to go to Apex triggers, classes, etc.
  • Process Builder and Flow support invocable apex so, we don’t need to write code from scratch.
  • Flow also supports response from Apex Class but not the Process Builder.



Mukul Mahawariya

4x Salesforce Certified | Trailhead Ranger | Salesforce Enthusiast