Skip to main content

Salesforce - Invoke Apex from Visual Flows



This post will brief you about how one can invoke an Apex class from Visual Flows.

Important Note: The method which you would like to invoke should be marked as @InvocableMethod  and the variables which you would like use in and out of Flow, we need to mark them as @InvocableVariable

Best Practices : Make 2 wrapper classes. One for getting the values from Flow to Apex and other wrapper class is to get the values from Apex to Flow.

The below sample code explains how you can get a detail in and out of the flow.

Use Case : We ask user to enter the Account ID which they want to update and New Name which they want to update on the entered Account ID.

Note: Since this is for the demo purpose, we are asking user to enter the Account ID (SFDC 15/18 digit ID ). In Ideal scenario we can invoke the Flow from custom button/links. ( Refer This)



Here we created a Small Visual Flow which has 2 screens ( 1. For asking details from user and other for Showing the success/failure message )

Screen 1: Flow Diagram Overview ( Part 1 )

Flow Diagram

Screen 1 : Actual Flow screen visible to end user (Part 2)



 Screen 2 :  The Screen where user will enter the account id and new name for the account


 Screen 3: Creating the AccounSObj


Screen 4: Once user enters the 15/18 digit ID, we need to fill this value to AccounSobj created in previous step.


Screen 5 (Part 1 ): Calling the Apex Block from Flow - Passing the values to Apex


Screen 5 (Part 2 ): Calling the Apex Block from Flow - Getting the values from Apex into Flow



 Screen 6 : Happy End !! Knowing how you can utilize the values of flow variable set in previous step in a simple way. I am just using them on the Screen.



Comments

Post a Comment