Skip to main content

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.
    • Make sure to remove any spaces added by the Insert Field picklist. The URL should contain no spaces.
  1. Add parameters to assign values to the remaining input variables:
    • caseSubject
    • caseAccountId
    • caseType
  1. 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}.
  2. 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.

  1. 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.

  1. 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.
  1. Click the Highlights Panel.
  2. In the Highlights Panel properties pane, under Upgrade to Dynamic Actions, click Upgrade Now.
  3. Click the Migrate box, then click Next.
  4. 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.
  5. In the properties pane, click Add Action.
  6. In Search Actions, enter clone, select Clone Closed Case, and click Done.
  7. Drag the Clone Closed Case button to the top of the list.
  8. Click Save.
  9. 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

Salesforce 도움말에서 Trailhead 피드백을 공유하세요.

Trailhead에 관한 여러분의 의견에 귀 기울이겠습니다. 이제 Salesforce 도움말 사이트에서 언제든지 새로운 피드백 양식을 작성할 수 있습니다.

자세히 알아보기 의견 공유하기