đź“Ł Attention Salesforce Certified Trailblazers! Link your Trailhead and Webassessor accounts and maintain your credentials by December 14th. Learn more.

Distribute the Flow with a Custom Button

Activate the Flow

You’ve successfully created the flow, but it’s only accessible from Setup. Not to mention, until you activate it, only flow admins can run it.
  1. On the button bar, click Close.
    The Cloud Flow Designer closes, and the flow detail page opens.
  2. For the version you saved, click Activate.
Now any user can run this flow, as long as they have either:
  • The “Run Flows” user permission
  • The Flow User field enabled on their user detail page
But users can’t run anything if they don’t know where to find it. Let’s implement the flow so that your sales reps can find and use it easily.

Make Your Flows Look Like Lightning

Salesforce offers two runtime 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.
  1. From Setup, enter Automation in the Quick Find box, then select Process Automation Settings.
  2. Select Enable Lightning runtime for flows.
  3. Save your changes.


This setting only affects URL-based flows. That includes flows that are run from custom buttons or the Run button in the Cloud Flow Designer. For more details, see Flow Runtime Experiences.

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.
  1. Copy the flow’s URL.
    A view of the Flow Detail screen with the flow URL highlighted
  2. Create the custom button.
    1. From the object management settings for opportunities, go to Buttons, Links, and Actions.
    2. Click New Button or Link.
  3. Configure the custom button’s display properties.
    Field Value
    Label Calculate Discount
    Name Calculate_Discount
    Description Calculates a discount based on annual revenue
    Display Type Detail Page Button
    Behavior Display in new window
    Content Source URL
  4. Link the button to the flow using URL parameters.
    1. In the text box, paste the flow URL.
    2. At the end of the URL, append the following.
      Now, when the flow is called, two field values—AccountId and Id—are passed into the flow from the opportunity. The ID of the account that's associated with the opportunity, AccountId, gets assigned to the flow variable {!AccountID}. The ID of the opportunity itself, Id, gets assigned to the flow variable {!OpportunityID}.
      Here's what the URL should look like.
      A view of the text box with URL entered
    3. Verify that your URL is valid by clicking Check Syntax.
  5. Save the button.
    A dialog box appears to remind you to add the custom button to the opportunity page layout. Don’t worry, we’re doing that next.
  6. Click OK.
  7. Add the button to the opportunity page layout, so that it appears on all opportunity records.
    1. From the object management settings for opportunities, go to Page Layouts.
    2. Click Opportunity Layout.
      A view of the Opportunity Page Layouts related list with the Edit link highlighted
    3. In the left column, click Buttons.
    4. Click and drag Calculate Discount onto Custom Buttons.
      A view of the Opportunity Layout screen showing users where to drag the Calculate Discount button
    5. Click Save.
      Now, when sales reps visit an opportunity page in Salesforce they’ll see the Calculate Discount button at the top of the page.

Customize the Opportunity Page Layout

Soon, you’ll want to test the flow—just to make sure that everything works. Before you can do that, make sure that the Discount Percentage and Discounted Amount fields appear on the opportunity page layout.
  1. From the palette, drag the Discounted Amount and Discount Percentage fields into the Opportunity Information section.
  2. Verify that the page layout looks like this, and then save it.
    A view of the two fields added to the opportunity page layout

Create a Sample Opportunity

Just one more thing 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.

  1. Make sure that you have an account called Edge Communications and that its annual revenue is $139,000,000.
  2. Create an opportunity.
    If prompted to choose a record type, select B2B Sales and then click Continue.
  3. Configure the opportunity, and save it.
    Field Value
    Opportunity Name Edge Communications - 1 year contract
    Account Name Edge Communications
    Close Date A year from today
    Stage Proposal/Price Quote
    Amount 5,000,000

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.

  1. Click App Launcher icon and open the Sales app.
  2. Open the opportunity you created.
    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’s amount ($5,000,000) is $250,000. So the discounted amount for this opportunity should be $4,750,000. Let’s verify that the flow calculates the discount correctly.
  3. Click Calculate Discount, then click Open.
    Calculate Discount button
    A window appears notifying you that the flow has finished running.
  4. Close the window.
  5. To see the updated field values, refresh the page.
  6. Verify that Discount Percentage has a value of 5% and Discounted Amount has a value of $4,750,000.
    A view of the Opportunity Detail page after the discount has been calculated

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 cost. If so, offer the customer an even bigger discount.

For practice with other use cases, check out the other flow projects in Trailhead.