Cross-object field references in polymorphic relationships

A polymorphic relationship is a relationship between objects where one child record can reference to multiple parent objects of several different types. For example, the user field of a lead record could be a user or a queue. The WhatId field of an event could be an Account, a Campaign, or an Opportunity.  If you’re traversing from a lead to its owner ID, you have to add a special syntax to identify which object you want to refer when you say owner. Use the following syntax to reference a field on a related record:

{!Sov.polymorphicObjectName1:specificObjectName2.fieldName}

For example, to reference Lead's owner ID (user) who owns the lead record, use the following syntax: 

{!SovLead.Owner:User.Id}

The explanation of preceding syntax is as follows: 

  • Sov: This is the unique name for the sObject variable; in the preceding example, it is SovAsset
  • polymorphicObject: This is the API name for a polymorphic relationship for sObjectVariable's object type. In the preceding example, it is Owner
  • specificObjectName2: This is the API name for the object that you want to select from the polymorphic relationship. In the preceding example, it is User
  • fieldName: This is the name for the field that you want to reference on the last object in the expression. In the preceding example, it is Id.

Now we will use the Assignment element to specify {!SovAsset.Account.OwnerId} as the value for {!SovAsset.OwnerId}.

  1. To do this, navigate to the Palette tab and drag and drop the Assignment element onto the Flow canvas. It will open a new window for you, where you have to enter the following details:
    • Name: Enter the name for the Assignment element. In this case, enter Assign OwnerID as the name.
    • 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 Assignment element was created. When you select the Assignment element in the Explorer tab, the description appears in the Description pane.
    • Assignment: Select SovAsset.OwnerId as Variable; for Operator, select equals and for Value, manually enter {!SovAsset.Account.ownerId}

It will look like what is shown in the following screenshot:

  1. Once you are done, click on the OK button.
  2. At the end, we will use the Fast Update element to update the Asset record. To do that, navigate to the Palette tab and drag and drop the Fast Update element onto the Flow canvas. It will open a new window for you, where you have to enter the following details:
    • Name: Enter the name for the Fast Update element. In this case, enter Update asset owner as the name.
    • 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 Update element was created. When you select the Fast Update element in the Explorer tab, the description appears in the Description pane.
    • Variable: To create a record or multiple records, you can either use SObject variable or SObject Collection variable. In this case, select the SObject Collection variable SovAsset.
  1. Once you are done, click on the OK button.
  2. Use the connector to connect Fast LookupDecisionAssignment, and Fast Update elements, and set the Fast Lookup element as the start point, as shown in the following screenshot:
  1. Save your Flow with the Name field Update Assets owner and close the Flow Designer using the Close button; it will redirect you to Flow detail page. Form here, copy the Flow URL.
  2. To execute the Flow, we will create a custom button on the Asset object. To create a custom button, navigate to Setup | Build | Customize | Assets | Buttons, Links, and Actions and click on the New Button or Link button. Enter the name Update owner; for Display Type, select Detail Page Button; for Behavior, select Display in existing window without sidebar or header; for Content Source, select URL, and then construct the URL as per the business needs. In this case, 
    /flow/Update_Assets_owner?VarTAssetID={!Asset.Id}&retURL={!Asset.Id}.
  3. Once you're done, click on Save. The next task is to add a custom button on the Asset page layouts. Navigate to Setup | Build | Customize | Assets | Page Layouts, click on the Edit link, drag and drop the custom button Update Owner onto the page layout, and save the changes.
  1. To test this, identify an existing account where the account owner is another user. Then, create a new Asset for that account. Now you are the owner of that Asset record. Then, navigate to the newly created Asset, click on the Update Owner button, and it will update the Asset's owner from Asset's account owner. This means that Assets owner is now the same as the Account's owner. 
..................Content has been hidden....................

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