Search code examples
salesforcesoql

SOQL: Accessing the Contact Owner Field


I'm 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:

enter image description here

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.

SELECT Contact.Owner, Contact.Name, Contact.Rule_Class__c
       ^
ERROR at Row:1:Column:8
No such column 'Owner' on entity 'Contact'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

How can I grab this field?

Thank you!


Solution

  • That's a normal behavior for Relation fields

    enter image description here

    You can imagine OwnerId as an alias

    SELECT LastModifiedBy.Name,  LastModifiedBy.Id, LastModifiedById FROM Contact 
    
    SELECT CreatedBy.Name,  CreatedBy.Id, CreatedById FROM Contact
    

    Also use Workbench or Developer console or Eclipse to construct your queries instead of using salesforce setup interface

    Workbench enter image description here

    Developer Console enter image description here