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

Popular posts from this blog

Salesforce to Salesforce Integration using OAuth 2.0 and Named Credentials

Hello Everyone, After investing lot of time, I was able to Integrate with my own sandbox( you can say one Salesforce Instance to Other Salesforce instance ) I had a scenario where i had to call a rest method created and Exposed in my own sandbox. So I started digging on this as you guys are now. In order to perform OAuth with salesforce you need to perform 3 important steps. 1.        Create Connected App 2.        Create Auth. Provider 3.        Create Named Credentials Once you are authorized, you just need to write 5- 6 lines of code to invoke your REST method. So let’s gets started. As you know  Salesforce uses OAuth 2.0 now. So our job is to set up OAuth. Importantly, OAuth requires 4 important details and they are, Client ID, Secrete Key, User Name and Password. So how do we get them? Client ID and Secrete Key (AKA Client Secrete) can be obtained from Creating a Connected app. But what about User Name and Password?? User Name and Password can

Lightning - Passing value from Parent Component to Child Component

Hey Guys, This post I will try to cover some of the basics of Lightning Event. So if you have reached this post, I am assuming you have got some basic knowledge of Lightning framework. So, In brief Lightning Framework (LF ) works based on component and event driven modal. So when I say component  based, you might have seen that most of the codes are broken in to component in lightning development. You will understand more when you start creating one. There are few scenarios I would like to explain. Scene 1: Parent Component has one child and i want to pass some value from Parent to it's Child. Scene 2:Vice Versa Now .  I want to pass some value from Child Comp to it's parent components. How will you do ? There are 2 ways For Scene 1 and they are Way 1. Passing the value as Attribute Way 2. Sending the values using Lightning Methods. Way 1 is pretty simple. You will create a Attribute inside component 2(Child Comp) and will pass the required va