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
Akash PuneraAkash Punera 

Custom fields on user not accessible in soql for task object via owner lookup

[SELECT  id, owner.Any_Custom_Field_on_User__c 
FROM      Task]

This is returning an error.
Akash PuneraAkash Punera
Same query when run on account gets executed 
[SELECT  id, owner.Any_Custom_Field_on_User__c
FROM      Account]
Deepali KulshresthaDeepali Kulshrestha
Hi Akash
 
Greetings to you!

No, you can not use the custom field of the owner in Query. Also, you can not use all the standard field of the owner in Query. Only limit fields which are global like Owner.Id, Owner.Username, Owner.LastName ,Owner.FirstName ,Owner.Name, Owner. Title, Owner. Email etc can be used in Query.

If you required those field in the query you can create Formula field like Owner:User.custom_field__c .

So I added a custom formula field named Owner_Primary_Functions__c to Task object to represent the field value from related User objects for Task records. In my case, the formula was TEXT(Owner:User.Primary_Functions__c).

Now, this query works for me:

SELECT Id, Subject, Owner.Name, Owner_Primary_Functions__c FROM Task

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

Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com