Skip to main content

Build Lookup Logic to Find the Account Associated with This Opportunity

Create the Flow and Add Variables

Your sales reps will use a custom button to launch the flow. When clicked, the custom button calls the flow by its URL. When you use a custom button, you can append extra information, like field values, to the end of the URL. These values are known as URL parameters. URL parameters don’t support record variables, however, so for now we’ll use a regular flow variable. 

Create a flow and configure it to receive an account ID and an opportunity ID. Later, the flow uses those IDs to determine which discount to apply and where to apply it.

  1. From Setup, enter Flows in the Quick Find box, and then select Flows.
  2. Click New Flow.
  3. Make sure Start from Scratch is selected, and click Next.
  4. Select Autolaunched Flow (No Trigger) and click Create.

Create an Opportunity Variable

Let’s create a variable to store the opportunity’s ID.

  1. Click the Toggle Toolbox button to toggle the Toolbox.
  2. In the Manager tab, click New Resource.
  3. Configure the resource as a text variable.
    • For Resource Type, select Variable.
    • For API Name, enter OpportunityId.
    • For Description, enter Stores the ID number of the opportunity that triggered the flow.
    • For Data Type, select Text.
    • Check the Available for Input checkbox.

A view of the variable overlay for Opportunity ID

  1. Click Done.

Create an Account Variable

Next, create a variable to store the account ID.

  1. In the Manager tab, click New Resource.
  2. Configure the resource as a text variable.
    • For Resource Type, select Variable.
    • For API Name, enter AccountId.
    • For Description, enter Stores the ID number of the account associated with the opportunity.
    • For Data Type, select Text.
    • Check the Available for Input checkbox.
  3. Click Done.
  4. Verify that the OpportunityId and AccountId variables have been created. They should be listed under Variables.

The Flow Builder toolbox, with the new AccountId and OpportunityId variables

Save the Flow

Now it’s time to save the flow and define its key properties: name, description, type, and more.

  1. On the button bar, click Save.
  2. For Flow Label, enter Calculate Discounts.
    The Flow API Name field automatically populates based on this entry.
  3. For Description, enter Calculates a discount for an opportunity based on the annual revenue of the associated account

The Save flow overlay

  1. Click Save. An error appears, but that’s to be expected! After all, we haven’t added any elements yet. Dismiss the error.

Find the Account Associated with the Opportunity

To determine which discount to apply, the flow needs to know the account’s annual revenue. The flow has the ID of the account—it’s one of the values that the button passes into the flow. So it uses that ID to look up the account’s annual revenue in Salesforce. The Get Records element in Flow Builder lets you look up data in Salesforce. So let’s focus on Get Records.

In a Get Records element, the flow does two things. First, it looks up a Salesforce record by using criteria you set. Here, the flow finds an account record whose ID matches the flow variable AccountId. Second, the Get Records element automatically stores all the record values in a flow variable. When the flow moves to the next element, the values are assigned to the variable. This way, the flow can use that information to decide something later. Here, the Get Records element saves the value of the account’s AnnualRevenue field, in addition to other values.

  1. On the flow canvas, on the path after the Start element, click Add Element.
  2. Click Get Records.
  3. For Label, enter Find Related Account.
  4. For Object, select Account.
    This Get Records search is limited to account records.
  5. Set Condition Requirements to All Conditions Are Met (AND).
  6. Configure the filter fields.
    • For Field, select Id.
    • For Operator, select Equals.
    • For Value, select AccountId.

Here's what the first part of the overlay should look like. 

A view of the look up criteria configuration area in the Get Records element.

  1. Click Save.
在 Salesforce 帮助中分享 Trailhead 反馈

我们很想听听您使用 Trailhead 的经验——您现在可以随时从 Salesforce 帮助网站访问新的反馈表单。

了解更多 继续分享反馈