Invoke Apex method from Salesforce Flow Builder

Sometimes the out of the box functionality is not enough to automate all our processes


Andres Canavesi
Aug 04, 2022
Flow Builder is the replacement of Process Builder in Salesforce. Both of them are useful to automate several kinds of process but sometimes the out of the box functionality is not enough
featured image

What about Flow Builder

Flow Builder is the replacement of 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.
Salesforce setup - Search Flow Builder

Create Apex class with Invocable method

      
public class MyFlowClass {

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

Create the Flow

New Flow - Select type
Configure Flow
Configure Flow
Configure Flow
Configure 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.
Salesforce Developer Console logs

Reference

Photo by Lenny Kuhne on Unsplash