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
AbhiroopAbhiroop 

Retrieving the name of the owner of an account

Hi everyone;

 

How can I access (retrieve)  the name of the account owner using the name of the account. 

 

I found that account is in look up relationship with User , So running this query results in an error

 

 a) String acctname= [select Owner from account where name=: objAccount.Name];

 

 

Error: MyController2 Compile Error: No such column 'Owner' on entity 'Account'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 16 column 22

 

 

 

b) String acctname= [select a.$User.FirstName from account a where a.name=: objAccount.Name];

 

Error: MyController2 Compile Error: Didn't understand relationship '$User' 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. at line 16 column 22

 

Thanx in advance !!

sandeep@Salesforcesandeep@Salesforce

It is Possible using owner.Name for Account Name like

 

AccName = 'test';

 

so SOQL qould be 

[select owner.Name from Account Where name = : AccName ];

 

 

APathakAPathak
Try this : -

String acctname= [select Owner.name from account where name=: objAccount.Name limit 1][0].name;