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
Timmy AhluwaliaTimmy Ahluwalia 

SOql from event to User

HI,
I am trying to write the soql on event to fetch the custom field on USER object its failing. Please advise with some example.
Thanks
Best Answer chosen by Timmy Ahluwalia
SarvaniSarvani
Hi Timmy,

You cannot query your custom fields on the user object from event directly. You can only query few standard fields on the user object like name, email etc as below query.
select id, whoid, ownerid, owner.name, owner.email from event Limit 10

However, you can create a custom formula field  (Example: New_formulafield__c) on the Activities object with formula value like Owner:User.Custom_field__c. This will now populate your  custom formula field value with value in user record. And you can use query like below:
Select id, whoid, ownerid, New_formulafield__c from event limit 10
Refer to this link:
https://skaruz.com/salesforce-how-to-access-owner-custom-fields-in-a-soql-query/

I was able to fetch the values! Hope this helps, Please mark as best if it solves your problem.

Thanks

All Answers

SarvaniSarvani
Hi Timmy,

You cannot query your custom fields on the user object from event directly. You can only query few standard fields on the user object like name, email etc as below query.
select id, whoid, ownerid, owner.name, owner.email from event Limit 10

However, you can create a custom formula field  (Example: New_formulafield__c) on the Activities object with formula value like Owner:User.Custom_field__c. This will now populate your  custom formula field value with value in user record. And you can use query like below:
Select id, whoid, ownerid, New_formulafield__c from event limit 10
Refer to this link:
https://skaruz.com/salesforce-how-to-access-owner-custom-fields-in-a-soql-query/

I was able to fetch the values! Hope this helps, Please mark as best if it solves your problem.

Thanks
This was selected as the best answer
Timmy AhluwaliaTimmy Ahluwalia
Thanks Sarvani for the quick reply.