You need to sign in to do that
Don't have an account?
Relationship Query Question
I'm having trouble retrieving values from multiple SObjects.
I have a Custom Object which has a Master-Detail relationship to Account. Call it Object1. I need to retrieve values from the Account which are lookup fields to the User Object.
Select account__r.Name, account__r.Account_Manager From Object >this returns the account name and the userId of the Account Manager
I need to retrieve the Account Manager's name and e-mail
Select account__r.Account_Manager.Name, account__r.Account_Manager.email from Object1 > doesn't return anything.
I can retrieve the userId for the Account_Manager, but how do I then access the User fields for that Id?
Thanks!
The name field and the email field of the user object is not queryable
account__r.account_manager__r.name or account__r.account_manager__r.email
account__r.owner.name or account__r.owner.email
Hope this helps.
Thanks - that query runs, but the name and email values are always blank. If I run with Limit 10
I get back 10 user rows with no values. If I run the query with select from Account instead of from object1 it works.
Select account_manager__r.name,account_manager__r.email
From account - this works
Select account__r.account_manager__r.name,account__r.account_manager__r.email
From Object1 - this returns blank user rows
1) Make sure account_manager__c is not blank on the account you're querying; if so, it would indeed be null/blank.
2) System.debug(object1) won't show it, but System.debug(object1.account__r.account_manager__r.name) will.
3) You are limited to four relationships away upstream (e.g. account__r.account_manager__r.manager.manager.name) (but this doesn't seem to be a problem here).
Thanks for the sanity check. I'm going to try a different lookup field with the same query syntax.