Hands on 10 - conditional execution of a Flow with JavaScript

Until now, you learned how to execute Flow from a custom button or link and how to pass values to variables. Now, you will learn how to use JavaScript to pop up the Flow with the Screen element without human interaction.

Let's look at a business scenario. Helina Jolly is working as a system administrator in Universal Containers. She has created a Flow Create Leads that allows users to quickly create a lead and attach it to the campaign from the campaign detail page. For more details, refer to the Create Leads Flow under the Hands on 1 - creating leads section. She has received a requirement from her manager stating that users are not allowed to create leads if a campaign is not active.

We have already created a custom  Create Leads button to invoke it in the Hands on 1 - creating leads section. We will modify the existing code of the custom button and add JavaScript to fulfill the previously mentioned requirement. To do this, follow these instructions:

  1. Navigate to Setup | Build | Customize | Campaigns | Buttons, Links, and Actions and click on the Create Lead button. Then, click on Edit to modify the button code. Change the Behavior field to Execute JavaScript; for Content Source, select OnClick JavaScript and then replace the old script with the new script mentioned in the following code:
        //Mandatory by Salesforce to run OnClick JavaScript 

{!RequireScript("/soap/ajax/10.0/connection.js")}

if ({!Campaign.IsActive } == true)
{
window.open('/flow/Create_Leads?CampaignID=
{!Campaign.Id}&retURL={!Campaign.Id}');
}
else
{
alert('You are not authorized to create Leads for Inactive
Campaign');
}
  1. Once you are done, click on the Save button:

Now if the user tries to click on the Create Lead button, and the campaign is not active, it will prompt an alert or send a message to the users, as shown in the preceding screenshot. 

As of Spring'17 release, Onclick Javascript Buttons are not supported on Lightning Experience. 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.146.87