You need to sign in to do that
Don't have an account?
Karthik j
How to write child to parent query for task object
Hi
I want write a soql query on the Task object to get a custom field on its parent. whatid is the relationship field between Taskand its parent. I wrote this query but it throwing error.
select id,what.Program_Name__c from Task
How I can achieve this.
Thanks in advance
I want write a soql query on the Task object to get a custom field on its parent. whatid is the relationship field between Taskand its parent. I wrote this query but it throwing error.
select id,what.Program_Name__c from Task
How I can achieve this.
Thanks in advance
Try Below Query Please Mark It As Best Answer If It Helps
Thank You!
Your ask is similar to https://salesforce.stackexchange.com/questions/50995/how-do-i-access-custom-fields-of-task-parent-record-using-soql
WhatId is a polymorphic lookup field: it can refer to many different object types. Unless your org has the special SOQL Polymorphism feature turned on, you need to structure your relationship queries differently than standard SOQL dot notation.
Across the WhatId relationship, you can access at least the Type and Name fields with simple dot notation (SELECT What.Name, What.Type FROM Task WHERE ...)
However, if you want more data, you'll have to perform an entirely separate query that will vary by the type of the What entity.
If you are using Apex, you can break it into two separate queries. Reference: https://salesforce.stackexchange.com/questions/220127/how-to-display-task-whatid-related-field-on-lightning-page
Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you