I am running the following sfdx command to export Accounts, Contacts, and Opportunities. However, I am running into the following error messages below.


  1. How can I export the Accounts, Contacts, and Opportunities using sfdx force:data:tree:export?

What I tried:

sfdx force:data:tree:export -u myenv -q myfolder/account-query -d myfolder/accounts --prefix data-export --outputdir myfolder/accounts/ --plan

Error message:

Opportunity reference to account (someid) not found in query results

account-query file content

Select Id, Name, myfield__c \
,(Select Id, FirstName, LastName From Contacts) \
,(Select Id, Name From Opportunities where isClosed = false) \
From Account Where myfield__c != null Limit 200
  • The query looks fine. Would you be run a test by removing the custom field and where clause. Just the standard fields in query
    – manjit5190
    May 21, 2021 at 18:53
  • @manjit5190 it doesn't work without the where clause. I found the only workaround was to reduce the limit 200 down to limit 50. Something weird going on where the related objects (have an account id lookup) are not included in the account query doesn't work. Its the only thing I can think of but that didn't make sense to me May 21, 2021 at 19:40


Your Answer

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

Browse other questions tagged or ask your own question.