简体   繁体   中英

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:

在此输入图像描述

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!

That's a normal behavior for Relation fields

在此输入图像描述

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 在此输入图像描述

Developer Console 在此输入图像描述

This is strange:

"Select c.Owner.Email, c.Owner.Name, c.Owner.Username, c.OwnerId From Contact c Run the above in Developer Console--Query Editor"

https://developer.salesforce.com/forums/#!/feedtype=SINGLE_QUESTION_DETAIL&dc=General_Development&criteria=OPENQUESTIONS&id=906F0000000AvMHIA0

I wonder why Contact.Owner comes up as non-existent but Contact.Owner.Name is?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM