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
suji srinivasansuji srinivasan 

how to query from grandchild to parent in soql?

I created subcontact__c object  and created lookup relationship  with contact .child relationship Name -subcontacts

1.I tried to query child to parent  
select Name, Account.Name from Contact  - got response
2.when i trield to query grand child to parent  getting error 
select Name, Contact.Account.Name from subcontact__c - got error

Can you clarify me, why i didnt get response?
Thanks in Advance. 
Best Answer chosen by suji srinivasan
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Suji,

The query should be as below.
 
select Name, Contact__r.Account.Name from subcontact__c 

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Suji,

What is the Contact API name in the subcontact__c object?

Thanks,
 
suji srinivasansuji srinivasan
Hi sai,
Contact__c is the Contact API name in the subcontact__c object
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Suji,

The query should be as below.
 
select Name, Contact__r.Account.Name from subcontact__c 

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
This was selected as the best answer