function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PavanReddyPavanReddy 

what is soql polymorphysm? plz expedite on this

what is soql polymorphysm? plz expedite on this

souvik9086souvik9086

Hi,

 

In Task/Event, you can see a field named WhoId/WhatId. Those are called polymorphic fields as they have relations to multiple objects and to retrieve fields based on the related object in that field via SOQL in called SOQL Polymorphism.

 

SELECT Subject,
TYPEOF What
WHEN Account THEN Phone, NumberOfEmployees
WHEN Opportunity THEN Amount, CloseDate
END
FROM Event

 

TYPEOF clause is where the SOQL polymorphism starts.  If the field references an Account, the query will retrieve the referenced Account’s Phone andNumberOfEmployees fields. If the field references an Opportunity, the query will retrieve that Opportunity’s Amount andCloseDate fields.

 

For more reference

http://blogs.developerforce.com/tech-pubs/2012/09/soql-polymorphism-or-how-i-learned-to-love-the-polymorphic-relationship.html

 

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks