0

I wanted to export the objects data with record types from one scratch org to another scratch org. I tried with this command:

> sfdx force:data:tree:export -q c:/soql/cObject.soql -u SourceOrg -p -d OutputPath 

In the soql for the query, I attempt to get recordtype for each record using RecordType.DeveloperName in the SELECT clause.

I received the data with RecordType Name but when attempting to import the same json, it says RecordType is not valid. Here is the exact error:

ERROR running force:data:tree:import: {"hasErrors":true,"results":[{"referenceId":"cObject__cRef1","errors":[{"statusCode":"INVALID_FIELD","message":"Cannot reference a foreign key field RecordType.","fields":[]}]}]}**

Can you please let me know what mistake I did here.

2

1 Answer 1

1

Don't use force:data:tree:export, but Salesforce Data Move Utility , authored by Salesforce.

The export.json file is simple to build, all you need is to write a request, and export then import goes well, even if there are record types, dependencies....

The export.json file for your case could be the following:

    {
        "objects": [
            {
                "query": "SELECT all FROM YourObject__c",
                "operation": "Upsert",
                "externalId": "Name"
            }
        ]
    }

If you have a unique key different from Name, you can use composite external Id keys, like explained here.

If you want an assisted use of SFDMU, you can also use VsCode Sfdx Hardis UI (disclaimer: my company authors this open-source plugin), which contains a Data Import/Export menu.

enter image description here

Not the answer you're looking for? Browse other questions tagged .