CSV import-export examples.


Table of Contents



Example 1. Import AccountBrand.csv without providing Account.csv.

When the linked Accounts is already exist in the target org, you can simple do:

{
  "objectSets": [
    {
      "objects": [
        {
          "query": "SELECT Id FROM Account",
          "externalId": "ExternalID__c",
          "operation": "Readonly"
        },
        {
          "query": "SELECT Name, AccountId FROM AccountBrand",
          "operation": "Insert"
        }
      ]
    }
  ],
  "excludeIdsFromCSVFiles": "true"
}

AccountBrand.csv:

Name,Account.ExternalID__c
my_little_accBrand,AccExternalID123
Notes:
  • Since you omit Id column in the CSV, you have to set "excludeIdsFromCSVFiles": "true"

Example 2. Update object having composite external Id key.

When you want to update existing object with composite external Id key, it's not enough to provide each field contained in this key in separate csv column, but you have to provide the complete external Id value in one column using the following format:

{
    "objects": [
        {
            "query": "SELECT Id, Name, Key1__c, Key2__c FROM Account",
            "operation": "Update",
            "externalId": "Key1__c;Key2__c"
        }
    ],
  "excludeIdsFromCSVFiles": "true"
}

Account.csv:

Name,Account.$$Key1__c$Key2__c
Account1,"Key1;Key2"
Account2,"Key3;Key4"

Where the records are:

Account1:

Name = Account1, Key1__c = Key1, Key2__c=Key2

Account 2:

Name = Account2, Key1__c=Key3, Key2__c=Key4

Example 3. Import mixed Person Accounts and Business Accounts from the same Account.csv.

{
  "objects": [
    {
      "query": "SELECT Name, LastName FROM Account WHERE Name LIKE 'Test_%'",
      "operation": "Insert"
    }
  ]
}

Account.csv:

Id,Name,LastName,IsPersonAccount
0018d00000Gk3xbAAB,"Test_Person Account 0","Account 0",TRUE
0018d00000Gk3xcAAB,"Test_Business Account 0",,FALSE
Notes:
  • Pay attention that LastName field is NOT valid for BA but it's valid for PA, so you should provide extra column IsPersonAccount with true/false values to distinguish between type of Account you want to import.

  • You should provide at least Name field for BA account type and LastName for PA type.


References:

Full export.json format

Composite Extenal ID keys

Last updated on 29th Jan 2023