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
swapna muthiyaluswapna muthiyalu 

select field,oldvalue,newvalue,contactid, contact.name,account.name FROM contacthistory . i tried this query to fetch account name without using nested query, but throwing error.please help

i want to fetch account name from this query.
Raj VakatiRaj Vakati
Try this SOQL 
 
select field,oldvalue,newvalue,contactid, contact.name ,contact.Account.Name FROM contacthistory

 
swapna muthiyaluswapna muthiyalu
Thanks Raj, but is is giving [object,object] as output. i want the Account name in the result.
Raj VakatiRaj Vakati
Its a salesforce way of returning .. 
You can do some think like this 

1 . Create a formual field on contact that will return the name of account 
Formual : Account.Name
2. Use this SOQL as shown below 
contact.Acc_Name__c  is formula 
select field,oldvalue,newvalue,contactid, contact.name ,contact.Acc_Name__c FROM contacthistory

 
Ajay K DubediAjay K Dubedi
Hi Swapna,
    
(a)-IF contacthistory is the child of both Account and Contact. You can query without nested query.
(b)-IF contacthistory is the custom object you can use contacthistory__c.

Please check below url to understand Prent to child query and Child to Parent query.

    
1- https://salesforce.stackexchange.com/questions/127838/how-to-query-child-to-parent

2- https://developer.salesforce.com/forums/?id=9060G000000XbH5QAK

3- https://salesforce.stackexchange.com/questions/17916/child-to-parent-query-object-object-is-the-result    
    
Please let me know if you have any query.
Please mark it as best Answer if you find it helpful.

Thank You
Ajay Dubedi