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
rodrigorrodrigor 

How to do a parent to child SOQL query on User and Event objects

I am having an issue researching if it is possible to do a Parent to Child SOQL Query from User to Events. I can't find a chils relationship name to use, qould anybody know if that's possible or what is the relationship name? Here is my query so far:

 

SELECT User.id, User.Name, (Select id, Description, EndDateTime, StartDateTime, Subject, WhatId from Events) FROM User

 

I know there must be a chils relationship as an Event has a ownerid field which relates to User right?

 

I get the following error when I run the query above:

 

Didn't understand relationship 'Events' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.

 

Thanks in advance for your help!

Best Answer chosen by Admin (Salesforce Developers) 

All Answers

Avidev9Avidev9

OwnerId is a polymorphic field a special type of field that can point to User, QUeue. And are related using Sobject called as "Name". You cannot do direct parent to child relationship using ownerId

rodrigorrodrigor

Thanks Avidev9! So there is no way to get a list of events assigned/owned by a user in SOQL? Needs to be child to Parent? I was hoping I could have a result set grouped by User, 1 to many.

 

Thanks!

Neha LundNeha Lund

Hi,

 

You can use the below query to fectch data from Events and their owners.

 

SELECT ownerId, Owner.Name, id, Description, EndDateTime, StartDateTime, Subject, WhatId from Event

rodrigorrodrigor
Thanks for your help! I hope SFDC makes TypeOf queries turned on by default one day.