Sub topic 7
Insert, update, upsert, delete, and export
This chapter covers the five operations Data Loader offers for working with records. It assumes you have installed Data Loader and logged in, and that you can prepare a CSV file with a header row. Field mapping and relationship columns are covered in later chapters.
The five operations at a glance
Each operation reads a CSV file or writes one. The operation you choose decides how Salesforce treats each row.
| Operation | Input CSV needs | What it does |
|---|---|---|
| Insert | Field values, no Id | Creates a new record for every row |
| Update | Id plus the fields to change | Changes existing records matched by Id |
| Upsert | An Id or an external ID field, plus values | Updates a record if the key matches, otherwise creates one |
| Delete | Id only | Moves records to the Recycle Bin |
| Export | A SOQL query | Writes matching records to a CSV file |
Hard Delete and Export All also exist. Hard Delete skips the Recycle Bin, so use it only when you are sure. Export All includes deleted and archived records.
Insert
Insert creates one record per row. Here is a minimal file for the Account object.
Name,Phone,Industry,Website
Acme Corp,555-0100,Manufacturing,https://www.acme.example
Globex Ltd,555-0101,Technology,https://www.globex.exampleTo run it, choose Insert, select the Account object, pick the CSV file, check the mapping, and click Finish. Running the same file twice creates duplicate accounts, because insert never checks for existing records.
Export first, then update
Update needs the Salesforce Id of each record. The easiest way to get Ids is to export them. The query below also gives you a backup of the current values.
SELECT Id, Name, Phone, Industry FROM Account WHERE Industry = 'Energy'In Data Loader, choose Export, select Account, set a file name, and paste the query. The result is a CSV with an Id column.
An update file keeps the Id column and only the fields you want to change.
Id,Phone,Industry
001XXXXXXXXXXXXXXX,555-0199,Energy
001YYYYYXXXXXXXXXX,555-0198,RetailReplace the placeholder Ids with real ones from your export. An empty cell in an update file is ignored by default, so it does not clear the field. To write empty values, enable Insert null values in Settings. Be careful: this clears the field for every blank cell in the file.
Upsert
Upsert combines insert and update in one run. For each row, Data Loader looks for a match on a key you choose. The key is either the Salesforce Id or a field marked as an external ID. If it finds a match, it updates that record. If not, it creates a new one.
Use upsert when your file mixes new and existing records, or when the data comes from another system that has its own identifier. Upsert on an external ID also avoids the lookup-and-export step, because you never need the Salesforce Id.
Delete
Delete needs a CSV with a single column named Id.
Id
001XXXXXXXXXXXXXXX
001YYYYYYYYYYYYYYYDeleted records go to the Recycle Bin and can be restored for a limited time. Always export the records first so you have a copy of what you are removing. Deleting a parent record may also delete its child records, depending on the relationship.
Choosing and checking an operation
Before each run, confirm three things:
- The operation matches your intent. Insert on existing data makes duplicates.
- The object is correct. Data Loader lists all objects, and similar names are easy to confuse.
- The row count in the confirmation dialog matches what you expect.
Run a small test file of five to ten rows first. Review the success and error files that Data Loader writes after each run.
Exercise
You have a CSV of 500 customers from an outside billing system. Some already exist in Salesforce, and none of the rows contain a Salesforce Id. Each row has a billing system number. Which operation do you use, and what must be true of the billing number field in Salesforce?
Show answer
Use upsert. The billing number must be stored in a custom field that is marked as an external ID, ideally also unique. Upsert then updates rows whose number matches an existing record and inserts the rest.
Exercise
You run an update with a file where the Phone column is blank for some rows. Insert null values is off. What happens to the phone numbers on those records?
Show answer
They stay unchanged. Blank cells are ignored unless Insert null values is enabled.