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
Muhammad AmerMuhammad Amer 

Querying a related object using SOQL

Hi there

I have a custom field on my Account object, say 'refered_by__c'. This field contains the ID of another Account object.

I want to write a SOQL something like this (psedu query):

    select id, name, refered_by__c, <name of "refered_by__c"> from account 

Please advise how can I write this query using SOQL.

Thank you!
Best Answer chosen by Muhammad Amer
GhanshyamChoudhariGhanshyamChoudhari
Hi Saeed,
use below query
you need to use relationship query here to get output
Select id, name ,refered_by__r.Name From Account 

Mark as best answer if it helps you.
Thanks,
Ghanshyam Choudhari

All Answers

GhanshyamChoudhariGhanshyamChoudhari
Hi Saeed,
use below query
you need to use relationship query here to get output
Select id, name ,refered_by__r.Name From Account 

Mark as best answer if it helps you.
Thanks,
Ghanshyam Choudhari
This was selected as the best answer
Muhammad AmerMuhammad Amer
Thank you so much Ghanshyam - this is correct! 

While I was waiting for response, I also managed to find this out. Thanks again!
GhanshyamChoudhariGhanshyamChoudhari
Glad to know that.
please mark above answer as Best Answer so other people can also benefit. Thank you