Last Updated on April 3, 2022 by Rakesh Gupta
In Salesforce, relationship fields – such as Lookup, Master-Detail, or Hierarchical – allow a customer to connect one object with another object. Now imagine a use case where a customer wants to connect one object with multiple objects – i.e., relate a child object to multiple parents’ objects. In this blog, I will guide you through the process of, understanding and using, polymorphic relationships to relate a child object record with multiple parent objects. We will discuss, how we can use Salesforce Flow to update the parent object in case of a polymorphic relationship.
So let us get started. Suppose you want to connect an object with multiple parents objects – Student (child), College (parent), and Account (parent). Via a Lookup, or a Master-Detail, relationship, you can either connect a Student (child) record to a College (parent) record; or a Student (child) record to an Account (parent) record.
Now imagine a use case where you want to relate the Student (child) record to multiple parent records simultaneously – for example, a student (child) record to a College (parent) record and an Account (parent) record. If this is the case, then, you need to use the polymorphic key, to relate a child record, to multiple parents’ records.
Another example of the polymorphic relationship is Whoid and Whatid fields on the Event object. The WhatId field of an Event could be an Account, a Campaign, or an Order.
To summarize, when a field has a relationship with more than one object, it is called a polymorphic relationship. Using a Polymorphic Key, you can relate a single (child) field to multiple parent records – be it Account, Contact, Order, Quote, etc.
For example, if you have Queues enabled for Leads, a Lead Owner can be either a User or a Queue. A glance at the following image shows how a polymorphic key – refer to the right image below, ‘With Polymorphic Key’ – significantly streamlines an object mapping process.
As of now, the polymorphic relationship field is only available in the standard object and it is not possible to create a polymorphic relationship for custom objects in Salesforce. You may want to vote on this idea Custom Polymorphic Id field (WhoId/WhatId) if you think that it is an important feature for you.
Business Use Case
- Auto-close the Case.
- Update the Case description from the Task description.
Automation Champion Approach (I-do):
Before going ahead with the solution, you have to understand how to identify which object you want to update. For example, if you are traversing from a Task to its What ID (Related To), you have to add a special syntax to identify which object you want to refer to when you say, What ID. In our case, we want to update Case so, we will use Case object id 500 to identify the Case object from the What ID (Related To) field.Guided Practice (We-do):
There are 3 steps to solve Melissa’s business requirement using Record-Triggered Flow. We must:- Define flow properties for record-triggered flow
- Add a Decision element to check the Task status, Subject & WhatId
- Add an Update Records element to update the case status and description
Step 1: Define Flow Properties
- Click Setup.
- In the Quick Find box, type Flows.
- Select Flows then click on the New Flow.
- Select the Record-Triggered Flowoption, click on Create and configure the flow as follows:
- Object: Task
- Trigger the Flow When: A record is created or updated
- Set Entry Criteria
- Condition Requirements: None
- Optimize the Flow For Action and Related Records
- Click Done.

Step 2: Using Decision Element to Check Task Status, Subject & WhatId
Now we will use the Decision element to check if a task related to the case is successfully completed.
- On Flow Designer, click on the +icon and select the Decision element.
- Enter a name in the Label field; the API Name will auto-populate.
- Under Outcome Details, enter the Label the API Name will auto-populate.
- Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
- Row 1:
- Resource: {!$Record.WhatId}
- Operator: Is Null
- Value: {!$GlobalConstant.False}
- Click Add Condition
- Row 2:
- Resource: {!$Record.WhatId}
- Operator: Starts With
- Value: 500
- Click Add Condition
- Row 3:
- Resource: {!$Record.Status}
- Operator: Equals
- Value: Completed
- Click Add Condition
- Row 4:
- Resource: {!$Record.Subject}
- Operator: Equals
- Value: Case follow-up
- Row 1:
- When to Execute Outcome: Only if the record that triggered the flow to run is updated to meet the condition requirements.
- Click Done.
Step 3: Add Action – Update Records
The next step is to update the case status and description. We will use the Update Records element.
- On Flow Designer, below the Yes node, click on the +icon and select the Update Records element.
- Enter a name in the Label field; the API Name will auto-populate.
- For How to Find Records to Update and Set Their Values select Specify conditions to identify records, and set fields individually
- Object: Case
- Select All Conditions Are Met (AND).
- Set Filter Conditions
- Row 1:
- Field: Id
- Operator: Equals
- Value: {!$Record.WhatId}
- Row 1:
- Set Field Values for the Case Records
- Row 1:
- Field: Status
- Value: Closed
- Click Add Field
- Row 2:
- Field: Description
- Value: {!$Record.Description}
- Row 1:
- Click Done.
In the end, Melissa’s Flow will look like the following screenshot:
Once everything looks good, perform the steps below:
- Click Save.
- Enter Flow Label the API Name will auto-populate.
- Click Show Advanced.
- API Version for Running the Flow: 54
- Interview Label: Update Case on Task Completion {!$Flow.CurrentDateTime}
- Click Save.
Almost there! Once everything looks good, click the Activate button.
Proof of Concept
Next time, when a Task related to a Case, with subject Case follow-up, is completed, the flow (Created using Salesforce Flow) will fire and update the Case status and description fields.
Formative Assessment:
I want to hear from you!
What is one thing you learned from this post? How do you envision applying this new knowledge in the real world? Feel free to share in the comments below.
I tested the process in my dev org but stuck in “Define Criteria for this Action Group” as I found no whatid in the task field, nor case ID…
Look for “Related To”