Fields Mapping.
Table of Contents
Overview ⇧
Purpose: This feature simplifies data exports to different target data models by allowing the use of field mappings that accommodate differences in field names and structures between the source and target objects.
Example Scenario ⇧
Use case ⇧
Suppose you want to export Account data into another object called TestObject__c in a target system where field names and structures differ from the source. The Fields Mapping feature enables such cross-object data migration by defining a mapping scheme that translates source fields to their respective target fields.
Consider the following differences between the source object Account and the target object TestObject__c:
- TestObject__c.ParentTestObject__c is a self-referenced lookup to TestObject__c, similar to how Account.ParentId references Account.
- The external ID field for Account is ExternalID__c, while for TestObject__c, it is External_ID__c.
- Most other fields share the same names across both objects.
Here is the field mapping scheme for this scenario:
Source Field | Target Field |
---|---|
Account.Id | TestObject__c.Id |
Account.Name | TestObject__c.Name |
Account.ParentId | TestObject__c.ParentTestObject__c |
Account.ExternalID__c | TestObject__c.External_ID__c |
Account.TEST__c | TestObject__c.TEST__c |
Defining the Field Mapping in the Export Configuration ⇧
You can implement these mappings using the fieldMapping
property in the export.json
file as shown below:
"objects": [
{
"query": "SELECT Id, Name, ParentId, TEST__c FROM Account",
"operation": "Upsert",
"externalId": "ExternalID__c",
"useFieldMapping": true,
"fieldMapping": [
{
"targetObject": "TestObject__c"
},
{
"sourceField": "ParentId",
"targetField": "ParentTestObject__c"
},
{
"sourceField": "ExternalID__c",
"targetField": "External_ID__c"
}
]
}
]
Using an External CSV File for Field Mapping ⇧
For extensive field mappings across multiple objects and fields, consider using a dedicated CSV file named FieldMapping.csv
. This file should be placed in the same directory as your export.json
:
Here is an example of the FieldMapping.csv
content for the scenario described:
ObjectName | FieldName | Target |
---|---|---|
Account | TestObject__c | |
Account | ParentId | ParentTestObject__c |
Account | ExternalID__c | External_ID__c |
To activate field mapping for an object, set the object's useFieldMapping
property to true.
Notes:
- Ensure to include all fields specified in the
sourceField
in the object's query string. Fields mentioned in the mapping but omitted from the query will not be mapped. Fields included using the "multiselect" keyword will be ignored in the mapping schema. - Field and object names in the mapping schema are CASE SENSITIVE.
- The mapping applies only to fields that directly belong to the sobject and does not extend to queries on reference fields.