You need to sign in to do that
Don't have an account?
bohemianguy100
Relationship query - traverse Event down thru the WhatId
I am trying to query the Event object and traverse down thru the relatedTo (whatId) object and its corresponding fields. I was trying the following query in Eclipse:
Select e.What.Account_Name__c, e.What.Project__c, e.What.Confirmed_Start_Date__c, e.What.Account__c, e.WhatId, e.Account.Name, e.AccountId From Event e
I get the following error: No such column 'Account_Name__c' on entity Name. The field exists on a custom object Project_Request__c that is the relatedTo field on the Event.
How can I query the Project_Request__c object that is the relatedTo id on the event and access the fields on the Project_Request__c object from the Event object?
Thanks for any help.
The Who and What fields on the Task/Event objects are polymorphic fields - i.e. they can point to one of many different types of SObjects. Unfortunately you can't access any fields from a relationship field that is poloymorphic in SOQL. You'll have to meet your requirement with 2 SOQL queries. First query the Event object and make a Set of all 'WhatId' values. Then make another query to the Project_Request__c object for those set of records. Hope this helps.
All Answers
The Who and What fields on the Task/Event objects are polymorphic fields - i.e. they can point to one of many different types of SObjects. Unfortunately you can't access any fields from a relationship field that is poloymorphic in SOQL. You'll have to meet your requirement with 2 SOQL queries. First query the Event object and make a Set of all 'WhatId' values. Then make another query to the Project_Request__c object for those set of records. Hope this helps.
Hi
I believe, one cannot traverse down on activities (tasks or events).
Rather, you can use two queries. One query [on Event] to get the whatId and another query to get the required fields on the object [Project_Request__c] using the whatid.
Regards
Shruthi