1

I am attempting to export data using the FORCE:DATA:TREE:EXPORT CLI command, using a nested query like the following (for use in our Scratch-Orgs):

SELECT ...,(SELECT ... FROM My_Custom_Object__r) FROM Account WHERE ...

No matter what I try, I just keep getting errors. My question is two fold:

  1. Can this sort of nested query even be performed across __r relationships where there is no explicit foreign key field (field that would otherwise have an '@Ref' value), using the FORCE:DATA:TREE:EXPORT CLI command?

  2. If this is possible, how would an example of the nested query look for a __r relationship?

1

Look in Setup at the field on My_Custom_Object__c that is a Lookup or Master-Detail to Account. Under Master-Detail Options (or Lookup Options), find the Child Relationship Name. This is what gets suffixed with __r in a parent-to-child query. In this screenshot, the relationship name is Business_Lines:

enter image description here

So a parent-child query would look like:

SELECT Id, Name, (SELECT Id, Name FROM Business_Lines__r) FROM Account WHERE Name LIKE 'A%'

If the field in your example was created with defaults, then the relationship name is probably My_Custom_Objects and the query would be:

SELECT ...,(SELECT ... FROM My_Custom_Objects__r) FROM Account WHERE ...
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.