Build Lookup Logic to Find the Account Associated with This Opportunity
Create the Flow and Add Variables
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.
- From Setup, enter Flows in the Quick Find box, and then select Flows.
- Click New Flow.
- Select Autolaunched Flow (No Trigger), click Next, then click Freeform.
- Create a variable to store the opportunity ID.
- From Manager in the left pane, click New Resource.
- Configure the variable.
Field Value Resource Type Variable API Name OpportunityId Description Stores the ID number of the opportunity that triggered the flow Data Type Text Available for Input Selected - Click Done.
- Create a second variable to store the account ID.
- From Manager in the left pane, click New Resource.
- Configure the variable.
Field Value Resource Type Variable API Name AccountId Description Stores the ID number of the account associated with the opportunity Data Type Text Available for Input Selected
- Click Done.
- Verify that the OpportunityId and AccountId variables have been created. They should be listed under Variables.
Save the Flow
- On the button bar, click Save.
- For Flow Label, enter Calculate Discounts. The Flow API Name field automatically populates based on this entry.
- For Description, enter Calculates a discount for an opportunity based on the annual revenue of the associated account.
- Click Save. A warning dialog appears, but that’s to be expected! After all, we haven’t added any elements yet.
- Dismiss the warning.
Find the Account Associated with the Opportunity
In a Get Records element, the flow takes two actions. 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.
- From Elements in the left pane, click and drag a Get Records element onto the canvas.
- For Label, enter Find Related Account.
- For Object, select Account. This Get Records search is limited to account records.
- Set Condition Requirements to All Conditions Are Met (AND).
Field Value Field Id Operator Equals Value {!AccountId} - Click Done.
- Save your changes, and continue to ignore the warnings.