eltoroit / ETCopyData

SFDX Plugin to populate your scratch org and/or developer sandbox with data extracted from multiple sObjects.
113 stars 23 forks source link

Record Type Not Included? #1

Closed homerlex closed 5 years ago

homerlex commented 5 years ago

I just did a simple export/import on account:

{
    "now": "2018-12-05T12:40:35.780Z",
    "orgSource": "PTDataSource1",
    "orgDestination": "PTDataDestination1",
    "sObjectsData": [
        {
            "name": "Account",
            "ignoreFields": "OwnerId",
            "maxRecords": 20,
            "orderBy": "Name"
        }],
    "sObjectsMetadata": [],
    "rootFolder": "./ETDataFiles",
    "includeAllCustom": false,
    "stopOnErrors": true,
    "ignoreFields": "OwnerId, CreatedBy, CreatedDate, CurrencyIsoCode",
    "maxRecordsEach": -1,
    "deleteDestination": false,
    "pollingTimeout": 100000
}

The export worked but when i went to do an import each account record errored out with something like:

13:08:05.814Z   33      ERROR   Importer.js:229         *** [PTDataDestination1] Error importing [Account] record #13. CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY:record type missing for: Account:--
eltoroit commented 5 years ago

The error "record type missing" is because the sObject you are inserting has record types at the destination org and you are not providing the value for that. Try modifying the ETCopyData, and adding this entry in the sObjectsMetadata field and try again.

{
    "name": "RecordType",
    "fieldsToExport": "Id,DeveloperName",
    "matchBy": "DeveloperName"
}
homerlex commented 5 years ago

That helps. Thanks!

homerlex commented 5 years ago

Looking at this again, is matching by DeveloperName sufficient? Should it match by SObjectType + DeveloperName? ... and is it possible to "matchBy" multiple columns?

homerlex commented 5 years ago

I did something like following to include namespace and objecttype:

"sObjectsMetadata": [
        {
            "name": "RecordType",
            "fieldsToExport": "Id,DeveloperName,SObjectType,NamespacePrefix",
            "matchBy": "NamespacePrefix,SObjectType,DeveloperName",
            "orderBy": null,
            "where": null
        }
    ],

When I do an export I see that the RecordType.json looks good in both the source and destination files. The RecordTypeId is properly set in the source's Contact.json file. However, all the contact objects created in the destination are given the default record type instead of the record type that was assigned in the source.

eltoroit commented 5 years ago

Found and fixed the issue. I will update the source soon. The ETCopyData.json file needs to be changed to something like this:

{
    "name": "RecordType",
    "fieldsToExport": "Id,SobjectType,DeveloperName",
    "matchBy": "SobjectType, DeveloperName",
}

The matching will be done by SobjectType and DeveloperName. This fixes 2 different problems. Same recordType's developerName used for multiple sObjects and the value not being set properly. I believe this last issue was that it was not being properly found.