Confused about the behavior of polymorphic fields in SOQL, sometimes you can select parental fields through a polymorphic relationship and sometimes you cannot. For example on Task with Who (polymorphic to Lead or Contact),
Select Who.Name, Who.Id from Task
Name and Id Works for all polymorphic relationships as far as I can tell.
Select Who.Email, Who.Phone from Task
No error but no data is returned, although for some polymorphic fields like Case.Owner.Email this works without issue. Email and Phone exists on both Lead and Contact.
Select Who.Birthdate from Task where Who.Type = 'Contact'
Gives error: No such column 'Birthdate' on entity 'Name'. Birthdate exists on Contact but not Lead, but doesn't matter if I filter only Contacts or not.
Select Who.FirstName from Task
Works, FirstName exists on both Contact and Lead. Why doesn't Email, Phone, etc also work?
Just trying to understand the rules on when we can select parental fields from polymorphic relationships, general rule of thumb seems to be it will work if the Field name exists on all polymorphic objects and the results do not have mixed objects types but then there are some exceptions to this. We are an ISV and need a predictable way of knowing when we can allow our users to select from polymorphic fields and when we need to restrict it. Any insight would be helpful.