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
MicahHoover.ax1233MicahHoover.ax1233 

Getting grandfather field associated with object in SOQL

Say my schema looks like this:

 

ChildObject -> ParentObject -> GrandpaObject

 

And there is a field GrandpaObject__c.operational_area__c I want associated with my ChildObject.

 

I want to be able to grab all the ChildObjects from a batch in one big query but still have access to the field in the GrandpaObject for each ChildObject.

 

I'm guessing I use a child-parent relationship somehow, but I haven't seen any examples like that.

 

Does anyone have any idea?

Best Answer chosen by Admin (Salesforce Developers) 
ddsouzaddsouza

There are a couple of options you can try:

 

1) Create a custom field of type formula on Child Obj that just ouputs the value of GrandpaObject__c.operational_area__c

 

2) In  your query itself you can reference GrandpaObject__c.operational_area__c ... Something like 'Select Name, ParentObject__r.GrandpaObject__r.operational_area__c from ChildObject'

 

Hope that helps answer your question