Invoke Apex method from Salesforce Flow Builder

cute dolphine underwater
Reading Time: 2 minutes

In Salesforce, developers can invoke Apex methods from within the Flow Builder to execute code logic. Apex methods provide the capability of customizing Flows as needed, allowing users to create new features, validate data, and access records or web services. This post will walk you through how to invoke an Apex method from the Flow Builder.

What about Flow Builder

Flow Builder is the replacement for Process Builder in Salesforce. Both of them are useful to automate several kinds of processes but sometimes the out-of-the-box functionality is not enough and we have to go to a custom one such as some lines in an Apex class. Let’s see then how to invoke an Apex method through the Flow Builder.

Create Apex class with Invocable method

public class MyFlowClass {

    @InvocableMethod(label='My flow method'
                     description='A cool description about this method'
    public static void execute(List<id> accountIds){
        System.debug('account ids: '+accountIds);

Create the Flow

Remember to activate the Flow!

Test the Flow

Our flow will be executed every time we create or modify any account so let’s do that.
First of all open the Developer Console and go to the Logs tab. Open an account, edit any field and save it. After that see the log generated and make sure the debug line is present.



About the author

Andrés Canavesi
Andrés Canavesi

Software Engineer with 15+ experience in software development, specialized in Salesforce, Java and Node.js.

Related posts

Leave a Reply

%d bloggers like this: