Sub topic 8
Mapping CSV columns to fields
This chapter assumes you can edit CSV files, know Salesforce objects, records, and fields, and have a sandbox or Developer Edition org for practice. It also assumes you have installed Data Loader and can log in, and that you have seen the insert, update, upsert, delete, and export operations. Here the focus is on how Data Loader matches CSV columns to Salesforce fields, and on the errors that bad mappings cause.
What mapping does
A mapping is a pairing between one CSV column header and one Salesforce field API name. Data Loader reads each row, takes the value in each mapped column, and writes it to the paired field on the record. Columns you do not map are ignored. Fields you do not map are left empty on insert and left unchanged on update.
Mapping happens in a dialog near the end of each operation's wizard, after you choose the object and the CSV file. Required fields for the operation must be mapped, or Data Loader will not let you continue.
The Data Import Wizard handles this step in a browser page that shows the same kind of pairing. This chapter covers the Data Loader dialog and its saved mapping files.
Automatic mapping and its limits
The mapping dialog has an Auto-Match Fields to Columns button. It compares each CSV header to each field's label and API name and pairs those that match. The match ignores case, so phone pairs with Phone.
Auto-match is a starting point. It fails in these common cases:
- The header uses a different word than the field, such as
TelephoneforPhone. - The header contains extra spaces or a hidden character at the start of the file.
- The field is a custom field, whose API name ends in
__c, and the header uses only the label. - Two fields have similar labels, so the wrong one is paired.
Always read the result before you continue. A header that looks right can still pair with the wrong field.
Matching headers to API names
The most reliable way to get a clean auto-match is to name each CSV header after the field's API name. For a standard Account insert, the first file in this tutorial already does this:
Name,Phone,Industry,Website
Acme Corp,555-0100,Manufacturing,https://www.acme.example
Globex Ltd,555-0101,Technology,https://www.globex.exampleFor a custom field called Region on Account, the header would be Region__c. You can find API names under Setup, in Object Manager, on the Fields & Relationships page for the object.
Working in the mapping dialog
The dialog shows two panels. The upper panel lists the Salesforce fields available for the operation. The lower panel lists the CSV columns. You drag a CSV column onto a field to pair them. Data Loader shows the pairs in a table at the bottom.
Several details affect what you see:
- The field list depends on the operation. For an insert, only fields you can create are listed. For an update, only fields you can edit are listed, plus
Id. - Fields you cannot see because of field-level security do not appear. If a field is missing, check the permissions of the user who logged in.
- Read-only fields, such as formula fields and system audit fields, usually do not appear in the list.
- You can map a single CSV column to only one field in a pair. To load the same value into two fields, include the column twice in the CSV under different headers.
Update files and the Id column
For an update, the Id field must be mapped. Data Loader uses it to find the record to change. The remaining mapped columns hold the new values.
Id,Phone,Industry
001XXXXXXXXXXXXXXX,555-0199,Energy
001YYYYYYYYYYYYYYY,555-0198,RetailThe IDs above are placeholders. Replace them with real IDs from an export. A query like this one gives you both the IDs and a backup of the values you are about to change:
SELECT Id, Name, Phone, Industry FROM Account WHERE Industry = 'Energy'Because an update only writes the mapped fields, you can map a subset of columns and leave all other fields alone. This is a useful safety feature. Map only what you intend to change.
Saving and reusing a mapping
After you map the fields, you can click Save Mapping to write the pairs to an .sdl file. The next time you run a similar job, click Choose an Existing Map to load it.
A saved mapping file is plain text. Each line holds the CSV column on the left and the field API name on the right, separated by an equals sign. A mapping for the update file above looks like this:
Id=Id
Phone=Phone
Industry=IndustrySaved mappings matter for three reasons:
- They remove manual drag and drop for repeated jobs.
- They let a teammate run the same job with the same pairs.
- They are required for running Data Loader from the command line, which reads a mapping file instead of showing a dialog.
If a saved mapping names a column that is not in the new CSV, Data Loader reports an error or skips that pair. Keep the CSV headers stable across runs so the same mapping keeps working.
Mapping and data formats
Mapping decides which value goes to which field. It does not convert values. The value in the CSV must already be in a form the target field accepts. Common problems are:
| Field type | Accepted format | Typical problem |
|---|---|---|
| Date | `YYYY-MM-DD`, or a format matching the Data Loader date setting | A spreadsheet changes it to `03/04/2026` |
| Date/Time | ISO style, such as `2026-03-04T09:30:00Z` | Time zone is missing or wrong |
| Checkbox | `true` or `false`, or `1` or `0` | Values such as `Yes` are rejected |
| Picklist | An existing value, spelled exactly | A typo or an inactive value |
| Number, Currency | Digits with a period as the decimal separator | Thousands separators or currency symbols |
| Text | Within the field's length limit | Longer values are rejected |
A spreadsheet application often rewrites dates, drops leading zeros, and turns long numbers into scientific notation as it saves. Open the CSV in a text editor before loading to confirm the values are what you expect.
Blank values
An empty cell in a mapped column does not clear the field on an update by default. Data Loader treats it as no value supplied. To clear a field, write the text #N/A in the cell. Data Loader sends a null for that field. This works for fields that allow empty values, and fails for required fields.
An option in Settings called Insert Null Values changes the behavior for empty cells in Bulk API mode. Check your own org's settings before depending on it, and test on a few rows first.
Mapping relationship fields
A relationship is a lookup or master-detail link to another record. In the mapping dialog, a lookup field such as AccountId on Contact accepts a Salesforce ID. That is the simplest case: put the 15 or 18 character ID in the CSV column and pair it with AccountId.
When you do not have the IDs, you can use an external ID field on the parent object. In the dialog, relationship fields can be expanded to show the external ID fields of the related object. You pair your CSV column with the external ID field under that relationship, and Data Loader finds the parent for you. The next chapter covers this in detail. The point for mapping is that one lookup can have several possible targets in the dialog: the direct ID field, or an external ID field reached through the relationship.
Pick one per column. A CSV column of Salesforce IDs belongs with the ID field. A column of your own system keys belongs with the external ID field.
Troubleshooting mapping problems
| Symptom | Likely cause | Fix |
|---|---|---|
| A field is not in the field list | Field-level security, read-only field, or wrong operation | Check permissions and field type |
| Auto-match pairs nothing | Headers do not match labels or API names | Rename headers, or drag columns by hand |
| First column never matches | A byte order mark at the start of the file | Save as plain UTF-8 without a BOM |
| Values land in the wrong field | A wrong pair was accepted from auto-match | Review the mapping table before running |
| Rows fail with a format error | Dates, numbers, or booleans are in the wrong form | Fix the values in the CSV |
| Characters look garbled | The file encoding differs from the setting | Match the file encoding in Settings |
| Saved mapping fails | A header in the CSV was renamed | Restore the header or edit the `.sdl` file |
Check the mapping before a full run
A short routine catches most mistakes:
- Create a copy of the CSV with the first five rows.
- Run the operation on the copy and open the success file.
- Compare the values in the created or updated records with the CSV.
- Fix the mapping or the data, then run the full file.
The success and error files, covered in a later chapter, include each row's result, so this check takes only a few minutes.
Summary of rules
- Map every required field for the operation, and map
Idfor updates. - Name headers after API names to make auto-match dependable.
- Review the mapping table by eye, even after auto-match.
- Map only the fields you intend to change on an update.
- Save the mapping for repeated or automated jobs.
- Mapping does not convert data. Prepare values in the CSV first.
Exercise
You have a CSV with the columns Account Name, Telephone, and Segment. You want to update the Phone field and a custom picklist field with the API name Segment__c on existing Accounts, and leave every other field alone. What columns must the file also have, and how do you make the mapping reliable?
Show answer
The file needs an Id column holding each Account's Salesforce ID, because an update uses the mapped Id to find records. Rename the headers to Id, Phone, and Segment__c so auto-match works, or drag the columns by hand. Account Name can be dropped, or left unmapped, because it is not being changed. Map only Id, Phone, and Segment__c, review the mapping table, and save the mapping for reuse. Also confirm the Segment values match existing picklist values exactly.
Exercise
A teammate's update job ran without errors, but afterwards some Contacts have an empty Title. The CSV had a Title column with some blank cells. What most likely happened, and what would you change if the goal were to clear Title for specific rows?
Show answer
Blank cells were probably not the cause of the empty Titles, since by default an empty cell in a mapped column leaves the field unchanged on an update. Check whether the cells contained #N/A, which Data Loader treats as an instruction to set the field to null, or whether the Insert Null Values setting was turned on. To clear Title on purpose, put #N/A in only those rows' cells, and test it on a few rows first.