+ Start a Discussion
Bheema Donthi 24Bheema Donthi 24 

SOQL to pull the Event associated for User

I am trying to execute below basic SOQL and i get error. 

SELECT Id,(SELECT Id FROM Events) FROM User


Error - 
SELECT Id,(SELECT Id FROM Events) FROM User
                          ^
ERROR at Row:1:Column:27
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.
lnallurilnalluri
@Bheema 

Do you mean events associated with contacts or leads? OR Events created by users?
SELECT Id,(SELECT Id FROM Events) FROM Lead
 
SELECT Id,(SELECT Id FROM Events) FROM contact

 
Ajay K DubediAjay K Dubedi
Hi Bheema,

I have understood you problem. There is not any 'Event' object that exist on the User object.
That's why you are getting this error.

You may use two queries differently-

list <user> UserList = [SELECT Id FROM User];

list<Events> EventsList = [SELECT Id FROM Events where userId in : UserList ];


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com