What is an example of polymorphic lookup field in salesforce

Salesforce makes use of polymorphic relationship fields for native lookup fields that can reference multiple objects. The most common fields that use polymorphic relationships are Owner fields and Activity WhatId/WhoId fields.

A polymorphic field is one where the related object might be one of several different types of objects. For example, the Who relationship field of a Task can be a Contact or a Lead. To determine what kind a field is, call describeSObjects() on the object and examine the properties for the field.

Full
Answer

What is a polymorphic field in Salesforce?

A polymorphic field is one where the related object might be one of several different types of objects. For example, the Who relationship field of a Task can be a Contact or a Lead. To determine what kind a field is, call describeSObjects () on the object and examine the properties for the field.

What is the object type of a polymorphic field in soql?

In the Enterprise and Tooling API WSDLs, the object type of a polymorphic field depends on the version of the API. In API version 46.0 and later (and in versions where the Developer Preview part of the SOQL Polymorphism feature is enabled), the object type is sObject.

What is a polymorphic field?

Some fields are relationship fields, which means they can be used to get information about a related object. And some of those relationship fields are polymorphic fields. A polymorphic field is one where the related object might be one of several different types of objects.

Does soql support polymorphic relationships?

SOQL supports polymorphic relationships using the TYPEOF expression in a SELECT statement. TYPEOF is available in API version 46.0 and later. (It is also available in API version 26.0 and later as part of a Developer Preview.) Use TYPEOF in a SELECT statement to control which fields to query for each object type in a polymorphic relationship.


What is polymorphic lookup?

Multi-table lookups, a long awaited and much requested feature, are now live (Preview) for use via API. Multi-table lookups (also sometimes known as polymorphic lookups) allow the creation of a lookup in one table that looks up records in multiple other tables at once.


What is polymorphic relationship in Salesforce?

A polymorphic relationship is a relationship where the referenced objects can be one of several different object types. For example, the What relationship field in an Event can reference an Account, or a Campaign, or an Opportunity.


Which Java class programming technique shows the use of polymorphism?

Since both the definition are different in those classes, calc_grade() will work in different way for same input from different objects. Hence it shows polymorphism.


What do you mean by polymorphism in biology?

Polymorphism, as related to genomics, refers to the presence of two or more variant forms of a specific DNA sequence that can occur among different individuals or populations. The most common type of polymorphism involves variation at a single nucleotide (also called a single-nucleotide polymorphism, or SNP).


What are the most common polymorphic relationships in Salesforce?

The most common fields that use polymorphic relationships are Owner fields and Activity WhatId/WhoId fields. There may come a time when you need to work with these fields and be able to make certain decisions based on the type …


Can you use describe in SOQL?

You can use a describe call to access the information about parents for an object, or you can use the who, what, or owner fields (depending on the object) in SOQL queries. This object cannot be directly accessed. Here is the code I used to discover this issue.


The instanceof Operator Does Not Work

  • The Salesforce documentation on Working with Polymorphic Relationships provides an example where the instanceofoperator is used to determine the type of sObject that is represented by a polymorphic field. Here is an example of how this operator is used …and here is an example using this technique with a Task object to determine if the associated …

See more on iterativelogic.com


A Possible Explanation of Why The instanceof Operator Fails

  • After further research I found that the reason this might not work is because when querying the type of sObject a WhatId represents it returns ‘Name’ rather than the expected Account, Opportunity, Case, etc. Further research shows that a ‘Name’ object does indeed exist and it exists to support polymorphic relationships. This is why I am able to query the field ‘What.Type’ in the s…

See more on iterativelogic.com


A Way That Works

  • There are two other ways (that I am aware of) to determine the type of sObject that is referenced by a polymorphic field. Each technique has their own pros and cons. The first technique involves performing a describe call for the sObject that you want to work with and comparing the sObjects id prefix with the first 3 chars of the id that is stored in the WhatId field (or your polymorphic fiel…

See more on iterativelogic.com


Future Techniques For Working with Polymorphic Fields

  • Now that we have seen how to type polymorphic fields, let’s look into the future a bit. Salesforce is currently piloting a new expression for SOQL queries called TYPEOF. This new expression is only available as a developer preview at the moment and according to the documentation is available in API version 26.0 and later. What is particularly exciting about this new expression is that it pro…

See more on iterativelogic.com

Leave a Comment