Skip to main content
TrailblazerDX, the ultimate AI learning event is heading back to San Francisco March 6-7, 2024. Register Now and save 35% with code T24DEYE424.

Run an Autolaunched Flow from a Custom Button

Learning Objectives

After completing this unit, you’ll be able to:

  • Send data from a custom button to a flow.
  • Add a custom button to a Lightning record page by using Dynamic Actions.
Note

This badge is one stop along the way to Flow Builder proficiency. From start to finish, the Build Flows with Flow Builder trail guides you through learning all about Flow Builder. Follow this recommended sequence of badges to build strong process automation skills and become a Flow Builder expert.

Before You Start

This unit continues immediately from the previous unit. If you haven’t completed the steps in the Build an Autolaunched Flow unit, do that now. Otherwise you won’t be able to follow the steps here.

Assign Values to Input Variables

The button that you created contains the flow’s URL, but it doesn’t have any information from the record that the button is on. Specifically, we want to send the values in the fields that support technicians need, paired with their corresponding input variables, like this: caseId = {!Case.Id}

That format should look familiar. It’s the same format that you use to assign values to variables in an Assignment element: variable, operator, value (except that here we use the = symbol in place of the word Equals). In this example, caseId is the API name of the input variable and Case.Id is the record field that contains the value we want to assign to the input variable. The = operator works the same way it does in the Assignment element: it replaces the current value of the input variable with the value that follows the = symbol.

“”

Remember those input variables you created in the Clone Closed Case flow? For this scenario, we need to add them to the button’s URL as input variable assignments, formatted like this.

Flow Input Variable Record Field Assignment*

caseId

Case.Id

caseId={!Case.Id}

caseSubject

Case.Subject

caseSubject={!Case.Subject} 

caseAccountId

Case.AccountId

caseAccountId={!Case.AccountId} 

caseType

Case.Type

caseType={!Case.Type}

*Notice that there are no spaces in the assignment format.

Add URL Parameters to a Custom Button’s URL

To send variable assignments to the flow, we need to add those value assignments to the flow URL as parameters. URL parameters carry additional information to the server; in this case, to Salesforce. Parameters come at the end of the URL and they’re separated from the URL by a question mark, like this:
/flow/Clone_Closed_Case?<URL parameter>

Multiple URL parameters are separated by an ampersand, like this:
/flow/Clone_Closed_Case?<URL parameter 1>&<URL parameter 2>

Got it? Flowtastic! Let’s go update that custom button.

  1. If it’s not already open, open the Clone Closed Case button on the Case object.
  2. In the URL editor, add ? to the end of the URL to tell Salesforce that all the text that follows is parameters.
  3. Enter the API name of the case ID input variable: caseId
  4. Click Insert Operator and select = Equal.
  5. In the Insert Field picklist, select the field that you want the input variable to receive: Case ID.
    The editor inserts the field’s name surrounded by {! and }. This special formatting, called merge field notation, tells Salesforce to merge that field’s value into the URL.

    The URL corresponding to the description that follows.
    Now the URL is:
    /flow/Clone_Closed_Case?caseId={!Case.Id}

    • /flow/Clone_Closed_Case is the flow’s dedicated URL.
    • caseId is the API name of one of the flow’s input variables.
    • {!Case.Id} is the notation that tells Salesforce to merge in the Id field from the Case object.
  6. Add parameters to assign values to the remaining input variables:
    • caseSubject
    • caseAccountId
    • caseType
  7. Remember to enter the & symbol before each parameter except the first. That tells Salesforce that another parameter follows. Your URL should look like this (but without the highlighting).

    The 4 parameters are caseId={!Case.Id}&caseSubject={!Case.Subject}&caseAccountId={!Case.AccountId}&caseType={!Case.Type}.
  8. Click Check Syntax.
    The syntax checker reports errors in merge fields and formula functions in the URL. If there’s a problem with a merge field, try selecting the merge field in question and reselecting the field from the Insert Field list.

Define a Return Destination

Finally, you can tell the flow what page to automatically load when it finishes. How do we do that? You guessed it, another URL parameter: retURL.

  1. Enter &retURL=/ at the end of the URL.
  2. In the Insert Field picklist, select the ID of the record you want to load when the flow finishes: Case ID.
    In most cases, this is the ID of the record where the flow runs. Make sure that the ID’s merge field is at the very end of the URL.

    In this case, we want to send users back to the record where they clicked the button, so the final URL is:
    /flow/Clone_Closed_Case?caseId={!Case.Id}&caseSubject={!Case.Subject}&caseAccountId={!Case.AccountId}&caseType={!Case.Type}&retURL=/{!Case.Id}

    Note: How does this example retURL value work? Salesforce is looking for a complete URL, but we just added a record ID, right? There’s a special trick at work here. Leading with/ turns the ID into a relative URL. When Salesforce receives a relative URL with just the record ID (for example: /0018Z00002ijo06QAA), it takes the user directly to that record.

  3. Click Check Syntax.

    “”
    Note: Keep in mind that the Check Syntax button doesn’t check if your flow URL or input variables are wrong. To make sure the button is working as intended, build the flow and button in a sandbox and test them thoroughly.

  4. Save the button.

Place the Custom Button

Now you need to place the button so your support team can use it. There are two ways to display the button, and in this module, you learn the Dynamic Actions method. If you want to follow the Classic Page Layout method, follow the steps in the Create Custom Buttons and Links unit of the Lightning Experience Customization badge.

Note

If you use the Dynamic Actions method on a Lightning page, Salesforce permanently enables Dynamic Actions on that Lightning page. When Dynamic Actions is enabled, the page ignores buttons and actions on classic page layouts, and the only way you can set buttons and actions for that Lightning page is by using Lightning App Builder.

  1. In the Object Manager, open the Case object.
  2. Click Lightning Record Pages and click New to create a new record page.
    1. Label: Case Record Page
    2. Object: Case
    3. Select Clone Salesforce Default Page, then Case Grouped View Default.
    4. Click Done.

      The Lightning App Builder, with the Highlights Panel and the properties pane’s Upgrade Now button highlighted corresponding to the following steps.
  3. Click the Highlights Panel.
  4. In the Highlights Panel properties pane, under Upgrade to Dynamic Actions, click Upgrade Now.
  5. Click the Migrate box, then click Next.
  6. Select Case Layout and click Finish.
    With Dynamic Actions active on a Lightning record page, that page no longer uses classic page layouts to define the buttons in the Highlights Panel. Instead, you set each button individually in the Highlights Panel sidebar.
    The Highlights Panel properties pane, upgraded to show Dynamic Actions and the Add Action button.
  7. In the properties pane, click Add Action.
  8. In Search Actions, enter clone, select Clone Closed Case, and click Done.
  9. Drag the Clone Closed Case button to the top of the list.
  10. Click Save.
  11. Activate the page and make it the org default for Desktop and phone.

A case record, highlighting the new button, Clone Closed Case.

Congratulations, you’ve created a flow that runs from a button! Carry the flowmentum of your success on to the next unit; the flow must go on!

Resources

Keep learning for
free!
Sign up for an account to continue.
What’s in it for you?
  • Get personalized recommendations for your career goals
  • Practice your skills with hands-on challenges and quizzes
  • Track and share your progress with employers
  • Connect to mentorship and career opportunities