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 relationship to relate a child object record with multiple parent objects. We will discuss, how we can use Process Builder to update parent object in case of the 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 record.
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 Queue.
A glance at the following image shows how a polymorphic key – refer to 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
Let us start with a business use case. Melissa Howard is working as System administrator at Universal Containers(UC). At UC they are extensively using tasks to manage their Sales and Support processes. She has received following requirement from her manager – when a task with the subject – Case follow-up is successfully completed – and it is related to the Case object – then, do the following:
- Auto close the Case.
- Update the Case description from Task description.
Solution for the Above Business Requirement
To solve the preceding requirement, there are two approaches
- Use Process Builder and Visual Workflow both. (1) The process will fire when a Task is successfully closed and it is related to Case object; (2) It will trigger a Visual Workflow; and (3) we will use Visual Workflow to update the Case status and description.
- Create a Process on the Task object to update Related Case status and description.
To solve the preceding requirement, I am going to use the second route. 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 when you say, What ID. In our case, we want to update Case so, we will use Case object id 500 to identify Case object from What ID (Related To) field.
- Click on Name | Setup | App Setup | Create | Workflows & Approvals | Process Builder
- To create a new process from scratch, click on the New Button available on Process Management page. A popup will appear where you have to enter the Name (Use Auto update case from the task as name), API Name and Description as shown in the below screenshot:
- Once you are done, click on the Save button.
- Click on the Object node to add object and then select the Task object. For the entry criteria, Select when a record is created or edited, as shown in the below screenshot:
- Once you are done, click on the Save button.
- The next task is to add Process Criteria, so that process will only fire when a task related to the case is successfully completed. To do this click on Add Criteria, enter Name, Type of action and set filter conditions, and follow the instructions below
- Once you are done, click on the Save button.
- Now we have to add an Immediate action into the Process to update the Account Name field. Click on Add Action (Under Immediate actions), Select the type of action (In our case Update Records), and then fill the values into fields to define the action – as shown in the following screenshot:
In the preceding screenshot, for the Record Type choose Select a record related to the Task as shown in the following screenshot:
- Once you are done, click on the Save button.
- In the end, your Process will look like the following screenshot:
- Don’t forget to active the Process by clicking on the Activate button.
It’s time to test this feature
Next time, when a Task related to a Case, with subject Case follow-up, is completed, the process (Created using Process Builder) will fire and update the Case status and description fields.
Note: – I am thankful to Work-Relay and Smartcloud.io for sponsoring my blog.
Technical Editor and Proofreader: - Munira Majmundar
🎊 🎉 🤔 🛒 Hurry! Limited Time Offer! 🎊 🎉 🤔 🛒
![]() |
![]() |
Offer Ends: 15th August 2017
Use the following codes to get a discount on my books when you purchase it through packtpub.com
For Print Copies (15% discount):
“LSVWPBNB15” – Learning Salesforce Visual Workflow and Process Builder – Second Edition
“MSCRMANB15” – Mastering Salesforce CRM Administration
For eBooks (50% discount):
“LSVWPBNB50” – Learning Salesforce Visual Workflow and Process Builder – Second Edition
“MSCRMANB50” – Mastering Salesforce CRM Administration
Please feel free to share it with your family, friends, and colleagues!
2 thoughts on “Getting Started with Process Builder – Part 76 (Working with Polymorphic Relationship)”
Liz Wong
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…
Rakesh Gupta
Look for “Related To”