0

I have a custom object called "Department" and the following custom fields

  1. Department_Head__c - Lookup(User)
  2. Department_Name_cc - Text (80)

I'm trying to query out the department head's user information via the following query

select Department__c.Id, Department.User.Id from Department__c

Or

select Department__c.Id, (select User.Id, User.Username from Users) from Department__c

Both return the following error message:

Didn't understand relationship 'Department__c' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.

2

If you need the id, just type [Select Id...], without Department__c. Same for all the other fields, except lookups used as relationships.

To get the user ID you need to use the user lookup API Name, for the custom fields you created on Department__c.

[SELECT Id, Department_Head__c, Department_Head__r.Name FROM Department__c]

Id is the departments Id, Department_Head__c is the user id and you will get the users Name using Department_Head__r.Name. For every field from the user you will need to use the Department_Head__r as a relationship, except the ID, as shown in the example.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.