You need to sign in to do that
Don't have an account?

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!
You can use polymorphic queries with the Type field and TYPE OF operator. You will need to file a support case with Salesforce first to have them enabled in your org. See documentation at
http://www.salesforce.com/us/developer/docs/soql_sosl/Content/sforce_api_calls_soql_select_typeof.htm
http://blogs.developerforce.com/tech-pubs/2012/09/soql-polymorphism-or-how-i-learned-to-love-the-polymorphic-relationship.html
http://salesforce.stackexchange.com/questions/1649/soql-query-on-fields-related-by-polymorphic-lookups
Regards,
Kresimir
Apex Editor LS - free alternative to Force.com apex editor.
All Answers
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
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!
You can use polymorphic queries with the Type field and TYPE OF operator. You will need to file a support case with Salesforce first to have them enabled in your org. See documentation at
http://www.salesforce.com/us/developer/docs/soql_sosl/Content/sforce_api_calls_soql_select_typeof.htm
http://blogs.developerforce.com/tech-pubs/2012/09/soql-polymorphism-or-how-i-learned-to-love-the-polymorphic-relationship.html
http://salesforce.stackexchange.com/questions/1649/soql-query-on-fields-related-by-polymorphic-lookups
Regards,
Kresimir
Apex Editor LS - free alternative to Force.com apex editor.
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