Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I am running the following query:

SELECT Name, ManagerID FROM User

The result yields a User's name and their corresponding Manager's user ID.

How can I return the Manager's name instead of the ID in SOQL?

share|improve this question
    
is your ManagerID field is a custom field of the User object itself? –  highfive May 14 at 18:24
add comment

2 Answers 2

up vote 4 down vote accepted

A great way to learn SOQL is to use the Schema Browser in the Force.com Eclipse IDE. In the screen shots below, I browsed to the User object:

enter image description here

Then scrolled down to the ManagerId field (note it is of type reference), then clicked on Type Data > Reference To > User > Fullname

enter image description here

And, SFDC has automatically built the SOQL for you in the Query pane:

enter image description here

Note: The 'u' can be omitted from your SOQL

share|improve this answer
    
Very handy! I guess that SF uses "references" rather than JOINs. I am more used to the SQL syntax and didn't know how such relationships would translate to SF without a JOIN. –  Addikt May 15 at 15:04
    
Apparently when you run this query the entire Manager user object is returned, not just the name. I would have thought that the dot syntax would remedy this, but it didn't. I tried to run the code in both the IDE and Developer console with the same difficulty. Is there any way to get around this? –  Addikt May 16 at 12:21
add comment

Did you try this:

SELECT Name, ManagerID, Manager.Name FROM User

Manager is lookup to User

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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