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
shillshill 

SOQL Relationship Query Error

Hello,
 
I am trying to write a Salesforce Object Query that retrieves data from the Task entity, but also pulls lead/contact information based on the "WhoId" field.
 
If I run the following query, I have no problem getting a result set:
Select Id,Who.FirstName,Who.LastName From Task
 
If I add the "Email" field to the select list, I get an error:
Select Id,Who.Email,Who.FirstName,Who.LastName From Task
 
INVALID_FIELD:
Select Id,Who.Email,Who.FirstName,Who.LastName
          ^
ERROR at Row:1:Column:11
No such column 'Email' on entity 'Name'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.
 
Is the email field not supported in this kind of a query, or am I doing something wrong.
 
Any help would be greatly appreciated.
 
Thank you,
Scott
SuperfellSuperfell
Because the who relationship is polymorphic, there's only a very limited subset of fields available when the relationship is queried via SOQL-R, and email isn't one of them. You'll have to break it up into multiple queries.
shillshill
Thank you for the quick reply Simon!
 
Is there documentation I can take a look at that would tell me what fields are inlcuded in something like this (or perhaps which fields aren't?)
 
Thank you,
Scott
SuperfellSuperfell
IIRC, there's a section on polymorphic relationships in the API docs.