Creating A Custom Flow Button
In today’s tutorial we are going to focus on something simple, yet practical regarding flows. Currently salesforce doesn’t inherently give you an easy option to access your flows out of the box. So to get around this we can easily create a custom button to put right on our page layouts to launch flows directly.
If you have never created a flow before, let’s do so now. You can search “flow” in your setup toolbar search, or you can navigate to Create – > Workflow & Approvals -> Flows. From here click “new flow”. You can name it whatever you like for the sake of this tutorial. For my org, the lead object is used to keep track of possible new recruits applying to the space cadet program, so I am going to create a button that takes my employees to our intake process.
Once you start your new flow, navigate to the “Resources” pallette on your toolbar to the left, and double click “Variable” to open up a new variable creation screen. Now if you don’t know what a variable is used for, think of it as a bank of data that our flow can pull from to reference specific datas within our org so that we can build logic based on the data that is pulled.
Via Salesforce “You can use flow variables to store data that can be used throughout the flow and referenced as values for updating record fields.”
Essentially, we want to create a variable that will reference the “LeadId” so that when we launch our button, it will bring us to the lead that we launch from. The referenced data is fluid and not static because we used a variable with our flow. Let’s go ahead and fill out our variable.
It’s best practice to keep our default value as an empty string so if nothing is triggered, it stays blank. Next, we need a few screens to our flow so that we launch, we have something to look at to make sure our button is working. Under “Palette”, go ahead and drag a screen into your work area. Let’s just make this a basic welcome screen with a “Display Text” field with a simple introduction so we know what this flow is for. When you have filled out the screen, click “OK”.
Let’s go ahead and add in a second screen, in my case, i’ll name it “Intake Step One”. We are going to leave the screen blank for later use. Go ahead and drag an arrow from the Welcome Screen to our second screen, making the Welcome Screen our starting flow point (which is signified by the green arrow on the box).
In a new tab, go ahead and “Run” the flow, which can be found next to the save options. We want to keep this open to we can refer to the URL for our custom button.
Now it’s time to create our button. Go To Leads -> Buttons, Links, and Actions under Setup, and create a new custom button. Your label is what your button will be named on your page layout. So for my button, I am naming it “Space Cadet Intake”. We want this to be a “Detail Page Button”, and the behavior is up to you, but I want mine to display in a new window. For content source we will be referring to our flow’s URL.
So currently our flow URL is “https://na35.salesforce.com/flow/Space_Cadet_Intake/301410000000ycWAAQ”. This is currently static data, and we want to put in play the variable we created earlier so that our data referral can be fluid and be based on the LeadId. In order to do this we need to update the URL to use our variable. To do this we need to redirect our URL to our variable “varLeadId”, and have it reference a merge field of the “Lead Id”. To do this, take out the record identifier and replace it as such:
Once we save, we now have a custom button that will bring us to the flow based on the LeadId. Let’s go ahead and add this to our page layout so we can use the button on our leads. Go to Leads -> Page Layout, and click “Edit” to the layout you wish to add to button to. For me I will be using the default Lead Layout.
Navigate to “Buttons”, and drag your new custom button onto your page layout, and save. Now when you go to a lead, your custom button will be there and give you an easy way to launch your flow directly from the lead.
Using buttons on your objects to navigate directly to flows will make it much easier for your users to access the tools they need to access, now at the click of a button thanks to you!