0

I have a relationship between Account and MyCustomObject__c where Account.CustomField__c is a lookup to MyCustomObject__c. When I try to export the field on the Account and related records using sfdx, after using the export command below the Account.CustomField__c is not populated but both Account and MyCustomObject__c records are exported into their respective files.

Questions

  • How can I retrieve Accounts and MyCustomObject__c records using sfdx such that when uploaded both records will be created and Account.CustomField__c is populated?

Current result

  • Accounts and MyCustomObject__c are exported but Account.CustomField__c is blank

Expected Result

  • Accounts and MyCustomObject__c are exported and Account.CustomField__c is populated

Query that I tried but didn't work as per the expected result

Select Id, Name, CustomField__c,
(Select Id, Name From MyCustomObject__c)
From Account

Observations

  • If the CustomField__c value (which is an Id) is not within the Select Id, Name From MyCustomObject__c, the sfdx command does not execute and return an error message

sfdx command

sfdx force:data:tree:export --query "Select Id, Name, CustomField__c, (Select Id, Name From MyCustomObject__r) From Account" --prefix accounts --outputdir my/output/dir --plan
0

Try this instead -

sfdx force:data:tree:export --query "Select Id, Name, CustomField__c, (Select Id, Name From MyCustomObject__r) From Account" --prefix accounts --outputdir my/output/dir --plan

The relationship name should end with __r for CustomObject.

5
  • I tried using __r as well and it didn't work. I have already verified that the name of the MyCustomObject__r is correct Jun 16 at 17:33
  • What is the sfdx and cli version you are using?
    – pk1772
    Jun 16 at 17:37
  • sfdx-cli/7.94.3-a4e7c7955b Jun 16 at 17:38
  • Run sfdx plugins --core command to get the sfdx version. I am assuming you do have necessary permission to access the lookup field on Account object.
    – pk1772
    Jun 16 at 17:45
  • that outputs salesforcedx 51.6.0 (core) and sfdx-cli 7.94.3 (core) and yes I have modify all permissions on both objects Jun 16 at 18:23

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.