+ Start a Discussion
RajeevlsHydRajeevlsHyd 

Extract Owner ID details from Account

I want to extract ownerId and the user related details from Account , so writing the query :

 

SELECT Id,OwnerId,OwnerId__r.DefaultDivision FROM Account where Id in (....

 

Its giving error : 

Didn't understand relationship 'OwnerId__r' 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.

 

Please suggest.

Best Answer chosen by Admin (Salesforce Developers) 
Dhaval PanchalDhaval Panchal
Instead of below
SELECT Id,OwnerId,OwnerId__r.DefaultDivision FROM Account where Id in (....
use below

SELECT Id,OwnerId,Owner.DefaultDivision FROM Account where Id in (....

All Answers

Dhaval PanchalDhaval Panchal
Instead of below
SELECT Id,OwnerId,OwnerId__r.DefaultDivision FROM Account where Id in (....
use below

SELECT Id,OwnerId,Owner.DefaultDivision FROM Account where Id in (....
This was selected as the best answer
Dhaval PanchalDhaval Panchal
OwnerId is a standard field, so we do not need to add '__r' with standard lookup field. And If you want to get Owner Id, then use field OwnerId and if you want to get other fields related to Owner (User) use simple Owner (i.e. Owner.name, Owner.alias, Owner.email etc)

same is applicable for all other standard lookup field.
for example in Contact object, AccountId is a standard field and related to Account. If you want to extract AccountId, name etc you can write below query.

Select Id, FirstName, AccountId, Account.Name, Account.AccountNumber From Contact

I hope this will help you to understand your problem.
RajeevlsHydRajeevlsHyd

Thanks dapanchal !!! Is there any way we can save query records from Developer Console?

Dhaval PanchalDhaval Panchal
I don't know if we can save query records from Developer Console, But you can use Data Loader Or Force.com Explorer to execute and save result of SOQL query.