Distribute the Flow with a Custom Button
Activate the Flow
You’ve successfully created the flow, but it’s only accessible from Setup. Now it’s time to activate it so that sales reps can run it.
From the buttons bar in Flow Builder, click Activate. Now any user can run this flow, as long as:
- They have the “Run Flows” user permission.
- The Flow User field is enabled on their user detail page.
-
Override default behavior and restrict access to enabled profiles or permission sets is selected for the flow, and a profile or permission set gives them access to that flow.
For more details, see How Does Flow Security Work?
If they don’t know where to find it, users can’t run anything. Let’s distribute the flow so that your sales reps can find and use it easily.
Make Your Flows Look Like Lightning
Salesforce offers two run-time experiences that determine the look and feel when someone runs a flow. To make your flows blend in with Lightning Experience, make sure that Lightning runtime is enabled in your org.
- From Setup, enter
Automation
in the Quick Find box, and then select Process Automation Settings.
- Verify that Enable Lightning runtime for flows is selected.
- Save your changes.
Create a Custom Button
Create a custom button to display on opportunities in Salesforce. When sales reps click the button, the flow calculates a discount and updates the opportunity.
- From Setup, enter
Flows
in the Quick Find box, and then select Flows.
- Click the down arrow in the Calculate Discounts row, then click View Details and Versions.
- Copy the flow’s URL from the Flow Detail page.
- Click Object Manager from the top of the Setup page.
- Select Opportunity.
- Click Buttons, Links, and Actions.
- Click New Button or Link.
Next, configure the custom button.
- For Label, enter
Calculate Discount
.
- For Name, enter
Calculate_Discount
.
- For Description, enter
Calculates a discount based on annual revenue
.
- For Display Type, select Detail Page Button.
- For Behavior, select Display in new window.
- For Content Source, select URL.
- Link the button to the flow using URL parameters.
- In the text box, paste the flow’s URL that you got from the Flow Detail page.
- At the end of the URL, append the following:
?AccountId={!Opportunity.AccountId}&OpportunityId={!Opportunity.Id}
- Verify that your URL is valid by clicking Check Syntax.
When this button calls the flow, the URL passes two of the Opportunity’s field values—AccountId and OpportunityId—into the flow. The ID of the account that's associated with the opportunity, AccountId, is assigned to the flow variable AccountId. And the ID of the opportunity itself is assigned to the flow variable OpportunityId. Here's what the URL should look like.
- Click Save. You’ll get a reminder to add the custom button to the opportunity page layout. Don’t worry, we’re doing that next.
Add the Custom Button to the Opportunity Page Layout
- While still on the Opportunity page in Object Manager, click Page Layouts. Then click Opportunity Layout.
- Click the Buttons category, then click and drag the Calculate Discount button into the page layout’s Custom Buttons.
- Take a look at the Salesforce Mobile and Lightning Experience Actions section of the page layout. If you see buttons there, click the Mobile & Lightning Actions category and drag the Calculate Discount button to the end of the Salesforce Mobile and Lightning Experience Actions section.
- Click Save.
Now, when sales reps visit an opportunity page in Salesforce, they should see the Calculate Discount button at the top of the page.
Create a Sample Opportunity
There’s just one more thing to do before you can test the flow: create a sample opportunity so that the flow has something to update.
The sample opportunity is for a one-year service contract with Edge Communications, a Texas-based electronics company with $139,000,000 in annual revenue.
- In the App Launcher (), search for
Accounts
and select the Accounts object.
- Go to the Edge Communications account. On the Details tab, confirm the Annual Revenue field value is $139,000,000.
If Edge Communications is not listed under Accounts, search for it with the Search bar. Or create the Edge Communications account if it doesn’t already exist, and add its annual revenue.
- On the Related tab, find the Opportunities related list and click its New button.
- Create an opportunity.
- If prompted to choose a record type, select B2B Sales and then click Continue.
- For Opportunity Name, enter
Edge Communications - 1 year contract
.
- Confirm that Account Name is set to Edge Communications.
- For Close Date, enter a date that’s one year from today.
- For Stage, select Proposal/Price Quote.
- For Amount, enter
5000000
.
- Click Save.
- If prompted to choose a record type, select B2B Sales and then click Continue.
Test the Flow
Testing is an important part of building a flow. Doing so lets you fine-tune the flow’s behavior, identify and fix bugs, and otherwise make sure your users have a pleasant experience. And you benefit, because you’ll spend less time responding to panicked emails from your sales reps.
Calculate the discount for the opportunity that you created in the last step.
- If you’re not already there, navigate to the opportunity you just created: Edge Communications - 1 year contract.
- In the menu, click Calculate Discount and wait for a notification that the flow has finished running.
- After the flow finishes, go back to the Edge Communications - 1 year contract opportunity.
The account’s annual revenue is $139,000,000. Because that value exceeds $100,000,000 but is less than $200,000,000, the flow should apply a 5% discount. A 5% discount on the opportunity amount ($5,000,000) is $250,000. So the discounted amount for this opportunity should be $4,750,000.
- Verify that the Discount Percentage has a value of 5% and the Discounted Amount has a value of $4,750,000.
Take It Further
If you haven’t worked with flows before, you’ll soon find that existing flows make great starting points for new ones—particularly as your organization grows and changes. Take the discount calculator we created, for example.
- To limit the number of full discounts offered, configure the flow to require approval from a manager before it updates the record.
- To be more aggressive with the discount program, look up whether the last opportunity was lost on price. If so, offer the customer an even bigger discount.
For practice with other use cases, check out the other flow projects in Trailhead.