Record transformation examples.


Table of Contents



Example 1. Assign a default User (e.g. OwnerId lookup) to target record.

The configurations below assign default user Id to OwnerId lookup if the given user does not exist in the target org.

Using the core:RecordsTransform module.

The first solution uses the core:RecordsTransform and the constant sourceField pattern.

It allows to assign user Id dynamically by the given user's name which is usually the same in the source and in the target orgs.

Let's say, the Name of the default owner user to assign is: "Test Target User".

{
    "objects": [
        {
            "operation": "Upsert",
            "externalId": "Name",
            "query": "SELECT Id, Name, Phone, OwnerId from Account WHERE Name IN ('ACC_10000', 'ACC_10001')",
            "beforeUpdateAddons" : [
                {                        
                    "module" : "core:RecordsTransform",
                    "args": {
                        "fields": [
                            {
                                "alias": "ownerId",
                                "sourceObject": "Account",
                                "sourceField": "OwnerId"
                            },
                            {
                                "alias": "defaultOwnerId",
                                "sourceObject": "User",
                                "sourceField": "Id",
                                "isConstant": true,
                                "lookupSource": "target",
                                "lookupExpression": "source.Name == 'Test Target User'"
                            }
                        ],
                        "transformations": [
                            {
                                "targetObject": "Account",
                                "targetField": "OwnerId",
                                "formula": "formula.ownerId || formula.defaultOwnerId"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "promptOnMissingParentObjects": false
}

Using the ValueMapping.

The second solution uses ValuesMapping feature (this approach would be preferred when you know the exact target Owner Id value):

export.json:

{
    "objects": [
        {
            "operation": "Upsert",
            "externalId": "Name",
            "deleteOldData": true,
            "query": "SELECT Id, Name, Phone, OwnerId from Account WHERE Name IN ('ACC_10000', 'ACC_10001')",
            "useValuesMapping": true
        }
    ],
    "promptOnMissingParentObjects": false
}

ValueMapping.csv file:

ObjectName,FieldName,RawValue,Value
Account,OwnerId,/^$/,0058d0000054PvGAAU

Example 2. Clear all text fields in an sObject.

You can use the type_string Multiselect Keyword to select only string-type fields and apply the Data Anonymization feature to reset these fields.

Run the job in one-directional mode.

Below is a basic export.json configuration to help achieve this:

{

    "objects": [
        {
            "operation": "Update",
            "externalId": "Id",
            "query": "SELECT type_string FROM Account",
            "mockFields": [
                {
                    "name": "all",
                    "pattern": "c_set_value(null)",
                    "excludeNames": ["Name"] // This will exclude unwanted fields from being anonymizing
                }
            ],
            "updateWithMockData": true
        }
    ]
}

Example 3. Assign constant value to specific field.

{
    "objects": [
        {
            "operation": "Update",
            "externalId": "Name",
            "query": "SELECT OwnerId FROM Account"
        }
    ]
}

The example above assigns a constant value to the OwnerId field of an Account using the Values Mapping feature.

Create a ValueMapping.csv file with the following content:

ObjectName FieldName RawValue Value
Account OwnerId /(.+)/ 00530000003xqAb

Here, 00530000003xqAb is the constant value of the target user ID you want to assign to the OwnerId field.

Example 4: Reset All Checkbox Field Values to False

The configuration below uses the Values Mapping feature to reset all values for the checkbox field Test__c to false.

{
    "objects": [
        {
            "operation": "Update",
            "externalId": "Name",
            "query": "SELECT Test__c FROM Account"
        }
    ]
}

Create a ValueMapping.csv file with the following content to apply the changes:

ObjectName FieldName RawValue Value
Account Test__c true false

References:

core:RecordsTransform module

ValuesMapping feature

Last updated on 15th Apr 2024