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
Manibalan SampathkumarManibalan Sampathkumar 

SOQL Polymorphism

Hi,

Is SOQL Polymorphism generally available? Is it available in developer edition?  I tried executing the following SOQL query in Developer edition, but I didn't get the contact name and email though there are contact records which matches the criteria:

SELECT Id, (SELECT TYPEOF Relation WHEN Contact THEN Name, Email END FROM EventRelations) FROM Event WHERE ActivityDateTime<=TODAY

Please let me know. Thx!
Chandra Sekhar CH N VChandra Sekhar CH N V
Yes, SOQL polymorphism is allowed in salesforce. Please follow below links for reference :
https://developer.salesforce.com/blogs/tech-pubs/2012/09/soql-polymorphism-or-how-i-learned-to-love-the-polymorphic-relationship.html (https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_typeof.htm)
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_typeof.htm

I tried the same query but didn't run. I doubt whether 'EventRelation' is accepted as TYPEOF variable in your query. Also, usually you get your related object data using 'What' variable which does not support contact object.
 
Manibalan SampathkumarManibalan Sampathkumar
Thanks Chandra Sekhar for your response! Basically, what I want to do is that I want to get contact names and their emails who have accepted the meeting invitation which I can do it without SOQL polymorphism, but I would like to know if it can be done through SOQL polymorphism. 
Also, I tried the following query in Developer edition and it didn't return anything. Do we have to open a case with SF Support to enable SOQL Polymorphism in my Dev Org?

SELECT 
  TYPEOF What
    WHEN Account THEN Phone, NumberOfEmployees
    ELSE Name, Email
  END
FROM Event
Chandra Sekhar CH N VChandra Sekhar CH N V
There's no concept of enabling anything here. Your queries using SOQL polymorphism will run normally.

Also,  i tried your new query above and indeed showed be some rows returning !!!
Manibalan SampathkumarManibalan Sampathkumar
Ok sure and Thanks!