Skip to main content

Posts

Showing posts from July, 2017

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/fa

Salesforce Visual Flow - Invoking Flow from Custom Button/Custom Links

The following piece of code snippet will help you invoke a visual flow from Custom Button/ Custom Links. Prerequisites   : The flow which you are about to invoke should be active. This below sample snippet is a Custom Link created on USER object. Limitation : We cannot create a Custom Button on User Std Object in salesforce. Display Type : Detail Page Link Behavior : Execute JaveScript Content Source : OnClick JavaScript {!REQUIRESCRIPT("/soap/ajax/28.0/connection.js")}  {!REQUIRESCRIPT("/support/console/28.0/integration.js")}  {! IF( User.isActive , "allowInvokeFlowFunction() ;" ,"alert('The user seems to be Inactive');")} function allowInvokeFlowFunction(){ var url = '/flow/ You_Flow_API_Name ?inputUserID={!User.Id}';  if (sforce.console.isInConsole()) {        sforce.console.openPrimaryTab(null, url, true);  } else {        window.open(url,'_blank');  } } In the