Hands on 8 - using cross-object fields in Flow

When working with related (parent-child relationship) records in Flow, sometimes, you may want to refer to parent record fields. For example, when working with a contact record in Flow, you may want to refer to the Account Phone field or Contact Phone field. To get the accounts phone, you may need to use Record Lookup, which means you have to perform a DML operation. Now you can refer to parent record fields without performing any query (Record Lookup), that is, using a cross-object field reference similar to the cross-object formula in Salesforce. 

Let's look at a business scenario. Helina Jolly is working as a system administrator at Universal Containers. She received a requirement to develop a Flow through which sales directors can update the Asset's owner from the Asset's account's owner. Basically, her manager wants to place a button on the Asset detail page through which the sales director can invoke the Flow. 

To develop this Flow, follow these instructions:

  1. Navigate to Setup | Build | Create | Workflow & Approvals | Flows.
  2. Click on the New Flow button; this will open the Flow canvas.
  3. Create a Text variable to pass the Asset ID from the custom URL. To do that, navigate to the Resources tab and double-click on Variable, available under the CREATE NEW section. Create a Text variable VarTAssetID and set Input/Output Type as Input and Output.
  4. Now our next task is to get the complete details of the Asset's record. For this, we have to use the Fast Lookup element. The reason behind using Fast Lookup is that it allows you to save the outcomes in the SObject variable. Create an SObject variable SovAsset for the object type Asset, and set Input/Output Type as Input and Output, as shown in the following screenshot:
  1. Once you are done, click on the OK button.
  2. Now we will use the Fast Lookup element to store the asset's fields, including AccountId in an SObject variable called SovAsset. Navigate to the Palette tab and drag and drop the Fast Lookup element onto the canvas; it will open a new window for you, where you have to enter the following details:
    • Name: Enter the name for the Fast Lookup element. In this case, enter the name as Get asset details
    • Unique Name: This will be autopopulated based on the name.
    • Description: Write some meaningful text so that another developer/administrator can easily understand why this Fast Lookup element was created. When you select the Fast Lookup element in the Explorer tab, a description appears in the Description pane.
    • Lookup: Select the object for which you want to search the records. In this case, select the Asset object.
    • The next task is to define the search criteria. For this, map Id with the text variable VarTAssetID
    • Variable: Select the SObject variable SovAsset to store the asset details. Don't forget to select the Assign null to the variable if no records are found. checkbox. Finally, select fields whose values you want to store, in this case, select Id, OwnerId, and AccountId.

Refer to the following screenshot for more details:

  1. Once you are done, click on the OK button.
  2. Now we will add the Decision element to evaluate the SObject variable {!SovContract.AccountId}. If AccoundId is not null, then we can use cross-object field reference to update the asset's owner without using another record lookup element to get the account owner's ID. This will save you from performing one more DML operation to get the account owner's ID. Drag and drop the Decision element onto the Flow canvas. Enter the name as Was account set for asset and the Unique Name field will get autopopulated based on the name. Optionally, you can also add Description to the Decision element. Then, create two outcomes for the Decision element, which are as follows:
    • Found: Select the SObject variable SovAsset.AccountId for operator and select is null and the value {!$GlobalConstant.False}.
    • Not Found: Enter the name as True for DEFAULT OUTCOME.
It will look like what is shown in the following screenshot:
  1. Once you are done, click on the OK button.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.206.25