Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Object JSON Mappings

Anoop Singh edited this page Jan 9, 2019 · 3 revisions

Object Mappings in JSON

Objects in Salesforce can have are lookups, master-detail and hierarchical kind of relationships.

One of the input for this migration tool is that you need to create object mappings in JSON format (JSON Mapping Dictionary) for the objects that you want to migrate records for. In the following sections, we will cover some of the possible object mappings for different kind of simple and related objects.

Simple object - JSON Mapping

The JSON object mapping for a simple object will look like this. In this below example, lets assume that Pricebook2 has no other relationships. The tool will migrate all Pricebook2 records from source org where IsStandard is not equal to true, to the target org.

[
  {
    "parent": "Pricebook2",
    "where": "IsStandard != true"
  }
]

Object with lookups - JSON Mapping

In this example we will cover how to related the lookup objects in a JSON object mapping. Lets say, you want to migrate PricebookEntry records but PricebookEntry has lookups to Pricebook2 and Product2 objects. Create "lookups" structure that will identify the lookup field name, lookup object and a composite key to uniquely identify the lookup record.

To filter certain records, use "where" filter in JSON. If you don't want to migrate certain fields, make them part of unmappedFields array.

[
  {
    "parent": "PricebookEntry",
    "where": " IsActive = true AND Pricebook2.IsStandard = true ",
    "unmappedFields": ["ProductCode", "Name"],
    "lookups": [
      {
        "lookupMappedField": "Pricebook2Id",
        "lookupObject": "Pricebook2",
        "keys": ["Name","IsActive","IsStandard"]
      },
      {
        "lookupMappedField": "Product2Id",
        "lookupObject": "Product2",
        "where": "Name != null",
        "keys": ["Name"]
      }
    ]
  }
]

Objects with master detail - JSON Mapping

Lets say, you want to migrate Approval_Process__c and its child Approval_Step__c records from source org to target org. Create "childs" structure that will identify the child object name and parent reference field. In addition, since a child in turn can have more child, you can use sequence number.

{
    "parent": "Approval_Process__c",
    "children": [
      {
        "parentMappedField": "Approval_Process__c",
        "childObject": "Approval_Step__c",
        "sequence": 1
      }
    ]
}       

Objects with master detail and lookup - JSON Mapping

In this example, Pricebook2 is parent object, and PricebookEntry is child object. PricebookEntry has a lookup to Product2. Tool will assume that you have already migrated products, if not, then first create a JSON mapping for products, migrate them and then do migration of Pricebook2 and PricebookEntry using below mapping.

[
  {
    "parent": "Pricebook2",
    "where": " IsStandard = false ",
    "unmappedFields": ["IsStandard"],
    "children": [
      {
        "parentMappedField": "Pricebook2Id",
        "childObject": "PricebookEntry",
        "where": " Pricebook2.IsActive=true And Pricebook2Id != null And Product2Id != null ",
        "sequence": 1,
	"unmappedFields": ["ProductCode", "Name"],
        "lookups": [
          {
            "lookupMappedField": "Product2Id",
            "lookupObject": "Product2",
            "where": "Name != null",
            "keys": ["Name"]
          }
        ]
      }
    ]
  }
]

Objects with master detail (multi level) and lookup - JSON Mapping

Let's consider another use-case where more than one level of master-detail relationship. In below example, Approval_Exception__c standalone object. Approval_Process__c is parent object that has a child Approval_Step__c. Approval_Step__c in turn has two children Approval_Term_Condition__c and Approval_Exception_Condition__c. Approval_Term_Condition__c has a lookup to Approval_Process__c and Approval_Exception_Condition__c has lookup to Approval_Process__c and Approval_Exception__c objects.

Note the "keys" array for lookups, "key" array helps in identifying the lookup record uniquely.

Here's how JSON object mapping will look like:

[
  {
    "parent": "Approval_Exception__c"
  },
  {
    "parent": "Approval_Process__c",
    "unmappedFields": [],
    "children": [
      {
        "parentMappedField": "Approval_Process__c",
        "childObject": "Approval_Step__c",
        "sequence": 1,
        "children": [
          {
            "parentMappedField": "Approval_Step__c",
            "childObject": "Approval_Term_Condition__c",
            "sequence": 2,
            "lookups": [
              {
                "lookupMappedField": "Approval_Process__c",
                "lookupObject": "Approval_Process__c",
                "keys": ["Name","Active__c"]
              }
            ]
          },
          {
            "parentMappedField": "Approval_Step__c",
            "childObject": "Approval_Exception_Condition__c",
            "sequence": 2,
            "lookups": [
              {
                "lookupMappedField": "Approval_Process__c",
                "lookupObject": "Approval_Process__c",
                "keys": ["Name","Active__c"]
              },
              {
                "lookupMappedField": "Exception__c",
                "lookupObject": "Approval_Exception__c",
                "keys": ["Exception__c","Active__c"]
              }
            ]
          }
        ]
      }
    ]
  }
]

Objects with master-detail, hierarchical and lookup - JSON Mapping

You want to migrate Accounts, Opportunities and Assets from source org to target org. Account is parent object for Opportunity and Asset. In addition, an account can have parent account lookup, so it will be a lookup to self.

In this case, since we have hierarchical relationship as well, so we need to use refresh property on Account. And, we want to avoid creating duplicates in target, so we will use external id.

Here's how JSON object mapping will look like for Accounts/Opportunities/Assets:

[
  {
    "parent": "Account",
    "externalIdField": "ExternalKey__c",
    "where": " ExternalKey__c != null",
    "refresh": true,
    "unmappedFields": [
      "PhotoUrl",
      "IsPartner",
      "IsCustomerPortal",
      "IsPersonAccount"
    ],
    "children": [
      {
        "parentMappedField": "AccountId",
        "childObject": "Opportunity",
        "externalIdField": "ExternalKey__c",
        "where": " ExternalKey__c != null",
        "unmappedFields": [
          "IsClosed",
          "IsWon",
          "ForecastCategory",
          "HasOpportunityLineItem",
          "FiscalQuarter",
          "FiscalYear",
          "Fiscal",
          "HasOpenActivity",
          "HasOverdueTask"
        ],
        "sequence": 1
      },
      {
        "parentMappedField": "AccountId",
        "childObject": "Asset",
        "externalIdField": "ExternalKey__c",
        "where": " ExternalKey__c != null",
        "sequence": 2
      }
    ],
    "lookups": [
      {
        "lookupMappedField": "ParentId",
        "lookupObject": "Account",
        "where": " ExternalKey__c != null",
        "keys": ["Name","ExternalKey__c"]
      }
    ]
  }
]

Clone this wiki locally