Calling Invocable Apex Class from Flow

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

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.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mukul Mahawariya

4x Salesforce Certified | Trailhead Ranger | Salesforce Enthusiast