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 )
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.
Screen 2 : The Screen where user will enter the account id and new name for the account
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
Quite Interesting post!!! Thanks for posting such a useful post. I wish to read your upcoming post to enhance my skill set, keep blogging.
ReplyDeleteRegards,
Salesforce Training in Chennai|Salesforce Course in Chennai
I am so impressed by reading your article. Keep sharing with us.
ReplyDeleteSalesforce Training institutes in Chennai
Salesforce Course in Chennai
Very nice blog, Thank you for providing good information.
ReplyDeleteSalesforce certification Training in Chennai
Salesforce.com training in chennai
An effective blog for the people. Great job and thanks for giving such a useful blog.
ReplyDeleteVery useful. Done a good work.
salesforce training
salesforce course
salesforce certifications
salesforce training centres in bangalore
salesforce certification training in bangalore
salesforce developer training institutes in bangalore