You need to sign in to do that
Don't have an account?

select account name from a custom object
Hi all,
I have a custom object called "CO" and having a field called "User".
I am able to get Account ID now, but I would like to get Account Name insted.
Would someone let me know if there is a way to get Account Name from CO?
=================================
CO (CO__c)
----
Id
User (User__c) -> Contact
---------
Id
Company (Account) -> Account
---------
Id
Name
=================================
"User" : Lookup(Contact)
"Company": Lookup (Account)
This is what I have now.
select User__r.AccountId from CO__c where Id = 'xxxxxxx';
Thank you,
HG
I have a custom object called "CO" and having a field called "User".
I am able to get Account ID now, but I would like to get Account Name insted.
Would someone let me know if there is a way to get Account Name from CO?
=================================
CO (CO__c)
----
Id
User (User__c) -> Contact
---------
Id
Company (Account) -> Account
---------
Id
Name
=================================
"User" : Lookup(Contact)
"Company": Lookup (Account)
This is what I have now.
select User__r.AccountId from CO__c where Id = 'xxxxxxx';
Thank you,
HG
Please use below query :-
select User__r.Account.Name from CO__c where Id = 'xxxxxxx';
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
All Answers
Please use below query :-
select User__r.Account.Name from CO__c where Id = 'xxxxxxx';
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Thank you for the reply.
I have tried that, but I am getting "[object Object]" as the result.
Do you know how to fix it?
Thanks
HG
Run the below query from dev console, you will get the output in debug. Use similar sytax to fetch the data from list:
Mark solved if it does help you
Thanks for the query.
But I got an error message "The query has to start with 'FIND' or 'SELECT'".
Should I run it from some where else instead of Query Editor?
Thanks
HG
Run it on Anonymous Window, it works
List<CO__c> lstCo = [Select Id, User__r.Account.Name from CO__c limit 1];
system.debug('Account Name is'+lstCo[0].User__r.Account.Name);
Thank you for the info.
I was able to run it successfully on Anonymouse Window.
Thanks!
Welcome!