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
Venkatesh Battini 9Venkatesh Battini 9 

Regarding Execute Anonymous Window

Hello,
If I write the follwing SOQL querry in QUERRY EDITOR I am getting exact results(ID of Contact, Name of Contact and Name of Parent Account)
 
Note: We already know that Account is Parent of Contact
SELECT Id, Name, Account.name FROM Contact

If I execute same querry in Execute Anonymous window instead of  Name of Parent Account I am getting Parent Account Id.

Why I am getting like that will any one of you explain me and what should I do to get Name of Parent Account.
Thank you in advance.
KaranrajKaranraj
Store the Query result in a collection variable and then get the value of the parent record from the variable
List<contact> cnt = [SELECT Id, Name, Account.name FROM Contact Limit 1];
System.debug('Account' + cnt[0].Account.Name);

 
Venkatesh Battini 9Venkatesh Battini 9
Actually I want to display all the information which i have retrieved through SOQL querry so I am writing like this

List<contact> cnt = [SELECT Id, Name, Account.name FROM Contact];
for(contact c:cnt)
System.debug(c);


Its giving Account Id instead of Name of Parent Account.
KaranrajKaranraj
Its not a big deal, just simply formate your debug statement to get more details.
List<contact> cnt = [SELECT Id, Name, Account.name FROM Contact];
for(contact c:cnt)
System.debug('ContactID :' + c.Id + 'Contact Name :' +c.Name+'AccountName :' + c.Account.name);
Venkatesh Battini 9Venkatesh Battini 9
I can write like that Karanraj but I want to know the difference between them. Anyways thannks alot.
SunidharSunidhar
In contact object we have a lookup field as 'Account' which ia a lookup to account. Here the thing is the in front end it will store Account Name(API Name: Account) but in the backend it will store the Account Id (API Name: accountId), It is a default thing provided by salesforce.

So, while u debugging the contact list will store account Id in the backend as i told, but you can get the parent fields which ever u queried while using.