Sub topic 8
Mapping CSV columns to fields
This chapter assumes you can create and edit CSV files, know the basics of Salesforce objects and fields, and have run at least one Data Loader operation. Mapping is the step that tells the tool which CSV column goes into which Salesforce field. Most "the load ran but the data is wrong" problems start here.
How mapping works
After you choose an operation and a CSV file, Data Loader asks which object to use. It then opens a mapping dialog. The dialog has two sides: the fields of the Salesforce object, and the column headers read from your file. You pair them up, and each row of the CSV is then written field by field using those pairs.
Three rules apply to every mapping:
- Only mapped columns are loaded. An unmapped column is ignored.
- A field you do not map is left alone on insert, and left unchanged on update.
- One CSV column can feed one field. If you need the same value in two fields, repeat the column in the file under a second header.
Auto-match and manual mapping
In the mapping dialog, choose Auto-Match Fields to Columns. Data Loader compares each header with each field's API name and label, and pairs those that match. For the Account file from earlier, the headers Name, Phone, Industry, and Website match the standard fields directly.
Auto-match is a convenience, not a check. Review every pair, and fix the rest by dragging a column onto a field or by using the mapping controls in the dialog. Look for these cases:
- Custom fields end in
__c. A header calledRegionwill not matchRegion__cunless the label also matches. Using the API name as the header removes the doubt. - Headers with extra spaces or different spelling, such as
Phone Number, stay unmapped. - Read-only fields, such as formula fields, are not available as targets.
Header names that map cleanly
The simplest habit is to name columns after the field API names. The update file below shows the idea. Id identifies the record to change, and the other two columns are the fields to overwrite.
Id,Phone,Industry
001XXXXXXXXXXXXXXX,555-0199,Energy
001YYYYYYYYYYYYYYY,555-0198,RetailFor an update, Id must be mapped to the record ID field. If it is not, the operation cannot find the records, and every row fails.
Saving and reusing a mapping
Data Loader can save a mapping to an .sdl file with Save Mapping. Next time, choose Choose an Existing Map and load that file. This helps when you run the same file layout every week. It is also what the command-line version of Data Loader reads, so a mapping you build in the dialog carries over to automation.
A saved mapping pairs header names with field names. If the file's headers change, the pair no longer matches, so keep header names stable.
Common mapping errors
| Symptom | Likely cause | Fix |
|---|---|---|
| A column is missing from the list | The header row is blank or has a stray character | Open the CSV in a text editor and check the first line |
| Auto-match pairs nothing | Headers use neither labels nor API names | Rename headers or map by hand |
| Every row fails on update | `Id` is not mapped | Map the `Id` column to the Id field |
| Values land in the wrong field | A pair was dragged onto the wrong row | Re-check each pair before you click OK |
| A required field error on each row | The required field has no mapped column | Add the column and map it |
SELECT Id, Name, Phone, Industry FROM Account WHERE Industry = 'Energy'Exercise
You run an update on Account with the file Id,Phone,Industry. Every row fails, and the error file says the record could not be found. Which mapping problem should you check first, and why?
Show answer
Check that the Id column is mapped to the Account Id field. An update uses the ID to find each record. If Id is unmapped or mapped to another field, no record can be matched, so every row fails.
Exercise
Your file has a column named Region, and the target field's API name is Region__c. Auto-match left it unmapped. Give two ways to fix this.
Show answer
Map the column to Region__c by hand in the mapping dialog, or rename the header to Region__c and run auto-match again. You can then save the mapping so the fix is reused.