6

I am creating scripts to export and import test data for our sfdx scratch orgs. I've used the sfdx force:data:tree:export command with -p to generate my plan file, plus three object files (one parent (Account object), and two different child custom object types)

I'm at the point where I'm attempting import the plan into the target scratch org with sfdx force:data:tree:import, and I receive the following error:

MALFORMED_ID ChildObj2: id value of incorrect type: @namespace_xx__ChildObj2__cRef1 namespace_xx__ChildObj2__c ERROR: ERROR_HTTP_400.

Here is the record that is causing the error (in the file namespace_xx__ChildObj1__cs.json), if I remove the line referencing the ChildObj2 record the import works, but the record of course doesn't link to ChildObj2 once imported.

{
  "attributes": {
    "type": "namespace_xx__ChildObj1__c",
    "referenceId": "namespace_xx__ChildObj1__cRef2"
  },
  "namespace_xx__Client__c": "@AccountRef2",
  "namespace_xx__Display_Name__c": "Some Business ChildObj1",
  "namespace_xx__ChildObj2__c": "@namespace_xx__ChildObj2__cRef1",   <<<< THIS LINE <<<<
  "namespace_xx__ChildObj2_Created_Date__c": "2018-07-12",
  "namespace_xx__Open_Date__c": "2018-07-12T19:16:47.000+0000",
  "namespace_xx__Phone__c": "888-123-5678",
  "namespace_xx__Qualified__c": false,
  "namespace_xx__Status__c": "Converted",
  "namespace_xx__Total_Calls__c": 0,
  "namespace_xx__Total_Emails__c": 0,
  "RecordTypeId": "0123B0000003FzfQAE"
}

Here is the json file it is referencing (namespace_xx__ChildObj2__cs.json):

{
  "records": [
    {
      "attributes": {
        "type": "namespace_xx__ChildObj2__c",
        "referenceId": "namespace_xx__ChildObj2__cRef1"
      },
      "namespace_xx__Client__c": "@AccountRef2",
      "namespace_xx__Open_Date__c": "2018-07-12",
      "namespace_xx__Primary_ChildObj1__c": "@namespace_xx__ChildObj1__cRef2",
      "namespace_xx__Status__c": "Open",
      "RecordTypeId": "0123B0000003FzhQAE"
    }
  ]
}

Here is the plan file contents:

[
    {
        "sobject": "Account",
        "saveRefs": true,
        "resolveRefs": false,
        "files": [
            "Accounts.json"
        ]
    },
    {
        "sobject": "namespace_xx__ChildObj1__c",
        "saveRefs": true,
        "resolveRefs": true,
        "files": [
            "namespace_xx__ChildObj1__cs.json"
        ]
    },
    {
        "sobject": "namespace_xx__ChildObj2__c",
        "saveRefs": false,
        "resolveRefs": true,
        "files": [
            "namespace_xx__ChildObj2__cs.json"
        ]
    }
]

Any idea on why I'm receiving this error? Any assistance is appreciated, I've spent most of the day on this.

1

Make sure that "resolveRefs" and "saveRefs" are set to true. For you basically it should be enough to set "saveRefs" to true for litify_pm__ChildObj2__c. When sfdx cli inserts its (litify_pm__ChildObj2__) records the "saveRefs" flag tells if Ids should be cached (remembered) for use by other objects.

It is very well explained by sfdcfox at What Are saveRefs and resolveRefs?

{
        "sobject": "Account",
        "saveRefs": true,
        "resolveRefs": true,
        "files": [
            "Accounts.json"
        ]
    }
    {
        "sobject": "litify_pm__ChildObj2__c",
        "saveRefs": true,
        "resolveRefs": true,
        "files": [
            "litify_pm__ChildObj2__cs.json"
        ]
    }
  • Thank you for the reply and link! I thought the saveRefs was probably the problem, but when updated my plan file to "saveRefs: true" for ChildObj2, I received the same error. I even tried making all saveRefs and resolveRefs equal to "true". The only thing that gets rid of the error is removing the line in the ChildObj1 record that is referencing the ChildObj2 record, but the ChildObj1 record is not linked to ChildObj2 record after the import. – scottdev Jul 14 '18 at 0:21
  • The json files were created via the sfdx force:data:tree:export command, although I did some scripting to get the RecordTypeId from the target import org for these records. I've verified those are the correct Ids, and even tried removing the RecordTypeId key:value pair to make sure it is unrelated. Still not sure what the problem is!? – scottdev Jul 14 '18 at 0:21
0

I had the same error... It seems that SFDX tree:import is failing when field name has a number in it. Please look at this post here: https://developer.salesforce.com/forums/?id=9060G0000005OE3QAM

Hope it helps !

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.