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
Zachariah RosenbergZachariah Rosenberg 

SOQL: Accessing the Contact Owner Field

Hello,

Im trying to write a SOQL query that will grab one of the Contact object's standard fields "Contact Owner", which is a Lookup(User) field.

The field name is "Owner", but when I try to query

SELECT Contact.Owner FROM Contact

I get an error stating that there is no such field.

How can I grab this field?

Thank you!
Best Answer chosen by Zachariah Rosenberg
Deepak BalurDeepak Balur
Select c.Owner.Email, c.Owner.Name, c.Owner.Username, c.OwnerId From Contact c
Run the above in Developer Console--Query Editor

All Answers

Balaji Chowdary GarapatiBalaji Chowdary Garapati

Try the below:

Select OwnerId from contact 

Thanks,

balaji

Deepak BalurDeepak Balur
Select c.Owner.Email, c.Owner.Name, c.Owner.Username, c.OwnerId From Contact c
Run the above in Developer Console--Query Editor
This was selected as the best answer
Zachariah RosenbergZachariah Rosenberg
Thank you both for your responses. @Balaji, your answer did return a unique identifier, which is good. But Deepak's answer was what I was looking for. Might I ask why C.Owner comes up as non-existant but C.Owner.Name does?
Deepak BalurDeepak Balur
c is just a table alias. "c.Owner" does not exist as a field in Contacts instead it's Id is stored in the OwnerId field and hencer we need to use
c.OwnerId.