function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
lashaklashak 

Getting Account Owner Name from Opportunity

Hi All,

I don't think this is possible, but before I gave up and just ran two queries, I wanted to check with you smart folks.  I am trying to get the Account Owner Name and Employee number from an opportunity query.  I know I can get to the Account.OwnerId but that is as far as it goes without writing another query to the User object for the name and employee number.

 

Here is my query:

Select o.Id, o.Account.Business_Unit__c, o.Account.Sub_Status__c, o.Account.Official_Name__c,

o.Account.Status__c, o.Account.Client_ID__c, o.Account.OwnerId, o.Account.Industry, o.Account.Website,

o.Account.BillingCountry, o.Account.BillingPostalCode, o.Account.BillingState, o.Account.BillingCity,

o.Account.BillingStreet, o.Account.Id, o.AccountId From Opportunity o

Where o.StageName >= '6 - Closed/Won'

 

I also need to return the Account Owner Name and Employee number but I have come up empty thus far except writing another query to the User object where User.Id = o.Account.OwnerId. 

 

Any thoughts or suggestions will be greatly appreciated.

 

Thanks,

Steve

Best Answer chosen by Admin (Salesforce Developers) 
werewolfwerewolf

Easy enough, you can just do something like this:

 

Select o.AccountId, o.Account.Owner.Name, o.Account.Owner.Employee_Number__c  from Opportunity o

 

You can go as many as 5 parents high in a single query.