Can I also export some fields from the referenced parent sObjects using the child object query?


I have a parent object ParentObject__c and want to get all ParentObject__r.Name using the child query on the ChildObject__c. 

In my configuration:

  • The ChildObject__c is the child object
  • The ParentObject__c is the parent.

I am trying to use this query, but it's not working:

SELECT Name, ParentObject__r.Name FROM ChildObject__c

What is wrong ?


You cant use subqueries and dots in your query. Use only the fields which owned by the object itself.

In order to extract the names of only those ParentObject__c records, which are related to the ChildObject__c records, create export.json containing two different objects with the following queries:

# Query defined for the ChidObject__c, ParentObject__c is a lookup field to the ParentObject__c object
SELECT Name, ParentObject__c FROM ChildObject__c

# Query defined for the ParentObject__c
SELECT Name FROM ParentObject__c
master=false # this is required, since we want to select all parent records which are referenced by the child records

Set master = false for the ParentObject__c object.

Last updated on 17th May 2023