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
Philippe Coste 2Philippe Coste 2 

RelationShip Query with custom field on standard object

My Object Acount has a custom field ProfessionalReference__c

When i execute in developer : select id, type,  what.name from task : It's work

When I execute : select id, type, what.ProfessionalReference__c from task.
It doesn't work. Could you please explain ?


Thanks
Steven NsubugaSteven Nsubuga
It should be  select id, type, Account.ProfessionalReference__c from task.
You have to do Account. in order to access the fields on Account from a query on Task.
Philippe Coste 2Philippe Coste 2
Ok, it's work.. THX
One more question please :
select id, type,  Owner.name from task ==> GOOD
select id, type,  Owner.ExternalID__c from task => NOT GOOD/...
Any Idea? 
 
VinayVinay (Salesforce Developers) 
Hi Philippe,

Try below query.
SELECT Id, Subject, TYPEOF Owner WHEN User THEN ExternalID__c END FROM Task

Reference:
https://developer.salesforce.com/blogs/tech-pubs/2012/09/soql-polymorphism-or-how-i-learned-to-love-the-polymorphic-relationship.html

Hope above information was helpful.

Please mark as Best Answer so that it can help others in the future.

Thanks,
Vinay Kumar