Skip to main content

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 above snippet allowInvokeFlowFunction ( ) is being called within IF condition is just to have a validation so that only Active Users can invoke the flow.
This step can be vomited and one can just invoke the Flow.

Note: If your flow is expecting any input then you can pass the required values as shown above. In the above example we are passing UserId to flow. If nothing is required, then this can be vomited.

inputUserID : This is a flow variable which is set to as  "Input Only ".

Flow Variable :



 Code Snippet:




Comments

Popular posts from this blog

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 Sho...

Rest Integration Test using Postmaster - OAuth 2.0

Hi , So you have created a Rest class and exposed it. At this stage you know how you can test this using Workbench. Ex: If your class name is : getAccountDetails which is expecting 2 parameters. then in the workbench, you will go to rest Explorer and select Get/Post based on the requirement and paste the URL something similar to this. /services/apexrest/CKDomain/getAccountDetails?Param1=1100055515&Param2=13706195 And BAM!!!! Everything looks fine. But in real time scenarios, you might want to give this endpoint URL to some other system (Say SAP/Oracle) and you want to test from your end before informing them about the endpoint URL. So how can we achieve this. There are many ways to test this and I prefer using Postman app for this. Install  Postman  from here. Now , In order to successfully receive a Rest call out from Other system to Salesforce , there are multiple auth techniques. I would like to use the most commonly used auth technique - OAuth 2.0 As...

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 ...