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. Read the rest of this entry!