How to handle Master-Detail relationships with SFDMU?


Question:

I'm facing challenges with inserting Authorization Form & Authorization Form Text using SFDMU, likely due to their Master-Detail relationship.

{
    "objects": [
        {
            "query": "SELECT Id, Name, RevisionNumber FROM AuthorizationForm",
            "externalId": "Name",
            "operation": "Upsert"
        },
        {
            "query": "SELECT Name, AuthorizationFormId FROM AuthorizationFormText",
            "externalId": "Id",
            "operation": "Upsert"
        }
    ]
}

When using Name as the externalId for AuthorizationForm, a dummy parent record with Name=ID0000000000000001 is created. Using Id as externalId causes missing parent lookups, preventing Authorization Form Texts from being inserted.

How can I ensure that both Master and Detail records are inserted correctly in one execution using SFDMU?


Answer:

SFDMU can handle Master-Detail (MD) and regular lookup relationships effectively.

However, for Master-Detail relationships where you're using an Upsert operation, using the record ID as an external ID may not function correctly for AuthorizationFormText due to the nuances of the Upsert operation which requires matching existing records.

To resolve this, ensure your CSV files are formatted correctly and set the flag "excludeIdsFromCSVFiles" to true. This flag helps manage ID fields in your CSVs, assuming they are not provided.

The correct CSV format for your scenario should look like this:

AuthorizationForm.csv:

Name,RevisionNumber
"Consent v1.0",1

AuthorizationFormText.csv:

Name,AuthorizationForm.Name
"Email Newsletter","Consent v1.0"
"Social media, such as Facebook or Instagram","Consent v1.0"
SMS,"Consent v1.0"

This setup allows you to manage Master-Detail relationships in one SFDMU run by ensuring that details reference their respective masters accurately.

Last updated on 20th Apr 2024