0

I am trying to run a SOQL query in workbench to pull details related to the Event (standard object) owner. I've been able to user Owner.Name within the query but haven't been able to successfully reference custom fields on the owner's user record. Any suggestions? I feel like I may have run into a polymorphic mess, but want to get other's thoughts as well. I've bolded the part of the query throwing the error.

SELECT Activity_Area__c,Subject,ActivityDate,Owner.Name,Owner.Tier_4__c 
FROM Event 
WHERE Activity_Area__c = 'Sales - Mobility' 
      AND (IsArchived = True OR IsArchived = False) 
      AND (ActivityDate = THIS_YEAR OR ActivityDate = LAST_YEAR)
1

You have indeed encountered a polymorphic lookup issue. If you examine the Event.OwnerId field in Workbench, you'll see the key

polymorphicForeignKey: true

This is the case because OwnerId can point to either a Queue or a User. As a consequence, you cannot directly access fields on either potential parent object by traversing the relationship. You can only see a tiny subset of fields, such as Type (the API name of the sObject that's actually pointed to), and Name.

You'll need to accumulate OwnerId values and perform a separate query.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.