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.

Example 4. Resetting target field values using CSV files.

Empty values in a CSV source file are treated differently depending on the engine used for updating the target org.

{
    "objects": [
        {
            "query": "SELECT Id, Website FROM Account",
            "operation": "Upsert",
            "externalId": "Name"
        }
    ]
}

Account.csv:

Id,Name,Website
001XXXXXXXXXXXXXX0,ACC_10000,
001XXXXXXXXXXXXXX1,ACC_10001,#N/A
  • When using REST API and Bulk API v1.0, both rows will reset the corresponding target Website fields.
  • When using Bulk API v2.0, the first row of the CSV file will not modify the corresponding Website target value, but the second (set as #N/A) will clear this value. This is because the CSV file format accepted by SFDMU when working in Bulk API v2.0 mode is compatible with the Valid CSV Record Rows Specification for Bulk API 2.0.

References:

Export.json File Specification

Composite Extenal ID keys

Last updated on 18th Aug 2024