Sub topic 2
Preparing your CSV file
A clean CSV file prevents most import failures before they start. This chapter covers how to build one that both the Data Import Wizard and Data Loader can read. It assumes you know what Salesforce objects, records, and fields are. You should also be able to edit a CSV file in a spreadsheet or text editor, and have a sandbox or Developer Edition org for practice.
What a CSV file is
A CSV file (comma-separated values) is a plain text file. Each line is one record. Commas separate the values on a line. The first line is a header row that names each column.
Name,Phone,Industry,Website
Acme Corp,555-0100,Manufacturing,https://www.acme.example
Globex Ltd,555-0101,Technology,https://www.globex.exampleThis is a minimal insert file for the Account object. The header has four column names. Each of the next two lines creates one Account. Both tools can load this file.
Salesforce reads the file as text. A spreadsheet adds formatting, formulas, and hidden characters that a CSV cannot hold. When you save, the spreadsheet application may change your data. The sections below show how to avoid that.
Build the header row
The header row tells the import tool which column goes with which field. Pick names that you can recognize and match later.
- Use field labels or API names. The Data Import Wizard and Data Loader both try to match headers to fields automatically. A header such as
Phonematches the Phone field. A header such asIndustrymatches the Industry field. Custom fields have API names that end in__c, for exampleRegion__c. Using the API name gives the best automatic match. - Keep one header per column. Do not repeat a header. Do not leave a header blank above a column that has data.
- Include only the columns you need. Extra columns are not a problem in Data Loader, because you can leave them unmapped. They add noise, though, and they are easy to map by mistake.
- Do not use merged cells or title rows. The header must be the first line of the file. A title line above it breaks the match.
If you are not sure what the headers should be, export a few existing records first. The export gives you the exact field names for the object, in a form you can edit.
Plan the columns for the operation
The columns you need depend on what you plan to do. The operation names are explained in a later chapter, but the file shape matters now.
| Operation | Columns the file needs |
|---|---|
| Insert | Every required field, plus any optional fields you want to set. No `Id` column. |
| Update | An `Id` column that identifies each record, plus only the fields you want to change. |
| Upsert | Either an `Id` column or an external ID column, plus the fields to set. |
| Delete | An `Id` column only. |
An update file looks like this:
Id,Phone,Industry
001XXXXXXXXXXXXXXX,555-0199,Energy
001YYYYYYYYYYYYYYY,555-0198,RetailThe Id column identifies the existing records. The other columns hold the new values. The IDs here are placeholders. Replace them with real IDs from an export. An update changes only the columns you include. A field that is not in the file keeps its current value.
Get record IDs from an export
You often need the Salesforce ID of each record before an update or delete. Run an export in Data Loader with a SOQL query. SOQL is the Salesforce query language, and it reads like SQL.
SELECT Id, Name, Phone, Industry FROM Account WHERE Industry = 'Energy'The export file contains the IDs. It also contains the current values, so it works as a backup of the records before you change them. Edit a copy of that file to build your update file. Keep the original unchanged.
Salesforce IDs come in two forms. The 15-character form is case sensitive. The 18-character form adds a three-character suffix and is case insensitive. Data Loader and the API accept both. If you open IDs in a tool that ignores case, such as some spreadsheet lookups, the 15-character form can look like a duplicate of another ID. Prefer the 18-character form.
Format values correctly
Salesforce validates each value against the field's data type. Most row errors come from a value that does not fit. The table lists common types and the format to use.
| Field type | Format to use | Common mistake |
|---|---|---|
| Text | Any characters up to the field length | A value longer than the limit is rejected |
| Number, Currency, Percent | Digits with a period as the decimal mark, such as `1250.50` | Thousands separators, currency symbols, or `%` signs |
| Date | `YYYY-MM-DD`, such as `2026-11-30` | Locale formats like `30/11/2026` |
| Date/Time | `YYYY-MM-DDThh:mm:ssZ`, such as `2026-11-30T11:28:00Z` | A missing time zone designator |
| Checkbox | `TRUE` or `FALSE` (`1` and `0` also work in Data Loader) | `Yes` or `No` |
| Picklist | The exact value from the picklist | A different spelling or letter case |
| Multi-select picklist | Values separated by semicolons, such as `Red;Blue` | Using commas |
| Email, URL, Phone | A well-formed value | Spaces or extra text |
Note that date and number handling depends on your user locale settings and on the tool. Data Loader reads dates according to your settings and accepts the ISO form shown above. The Data Import Wizard reads dates in the format of your Salesforce user locale. Writing dates in the ISO form is the safest choice for Data Loader. Check a sample row in the wizard before you load a large file.
Handle commas, quotes, and line breaks
A comma inside a value would be read as a column break. Wrap such a value in double quotes.
Name,Description
"Acme, Inc.","Makes anvils and ""rocket"" skates"
"Globex Ltd","Line one
line two"The rules follow the common CSV standard:
- A value with a comma, a double quote, or a line break must be wrapped in double quotes.
- A double quote inside a quoted value is written as two double quotes, as in
""rocket"". - A line break inside a quoted value stays part of that value. This is how a long text area is loaded.
Spreadsheet applications add these quotes for you when they save a CSV. If you build the file by hand or with a script, you must add them yourself. A missing quote shifts the later values one column to the right. That produces errors that look unrelated to the real cause.
Choose the file encoding
Save the file as UTF-8. This keeps accented letters and non-Latin characters intact. Without it, a name such as José can load as José.
- In Data Import Wizard, the file encoding is chosen on the upload step. Pick UTF-8 unless your file was saved in another encoding.
- In Data Loader, the setting is under the Settings dialog. Enable the option to read all CSVs with UTF-8 encoding if your data has non-English characters.
- Many spreadsheet programs offer a separate "CSV UTF-8" save option. Choose it rather than plain "CSV".
Leave blanks and clear values on purpose
An empty cell and a cleared value are different things in an update.
- In the Data Import Wizard, an empty cell does not overwrite an existing value.
- In Data Loader, an empty cell is also ignored by default. To erase a field, enter
#N/Ain the cell. Data Loader then sets the field to null. - If you turn on the Data Loader setting that inserts null values, empty cells will clear fields. Leave that setting off unless you mean it.
This matters when you start from an export and edit it. A blank in an update file is usually safe. A #N/A is a deliberate erase. Review both before you load.
Check the file before you load
Work through this list on every file. It takes a few minutes and avoids most failed loads.
- Open the file in a text editor. Confirm that the first line is the header and the delimiters are commas. In some regions a spreadsheet saves with semicolons.
- Check the row count. Compare it with the number of records you expect. Remember that the header takes one line.
- Cover the required fields. Every row needs a value for each required field on the object. Required fields are the topic of the next chapter.
- Look for duplicates in the file. Sort by the key columns, such as Name or Email. Two identical rows create two records.
- Trim spaces. A leading or trailing space makes
Energyfail as a picklist value. Use your spreadsheet's trim function. - Check the limits. The Data Import Wizard accepts up to 50,000 records per import. A file that large needs Data Loader. Data Loader handles far more rows, and its file size limits depend on the API you use.
- Test with a few rows. Load five to ten rows first, in a sandbox if possible. Open the result and compare it with the file.
Common errors in the file
| Symptom | Likely cause in the CSV |
|---|---|
| Every row fails with a missing field message | The header row is wrong, or a title row sits above it |
| Values appear in the wrong fields | An unquoted comma shifted the columns |
| Accented characters look garbled | The file is not UTF-8 |
| Date fields fail or show wrong dates | A locale date format in the file |
| Picklist values are rejected | A spelling difference or trailing space |
| IDs fail to match | A truncated or reformatted ID, or a column that is not text |
| Zero-padded codes lose their zeros | The spreadsheet converted the column to numbers |
Exercise
You export Account records with Id, Name, Phone, and Industry to build an update file. You want to change Industry for 200 accounts and leave every Phone value alone. Which columns should the update file contain, and what happens to Phone? Also name one check you should do after saving the file from a spreadsheet.
Show answer
Keep the Id and Industry columns and remove Name and Phone. The Id column identifies each record, and Industry holds the new value. Because Phone is not in the file, those values stay unchanged. After saving, open the CSV in a text editor to check that the encoding is UTF-8, that values with commas are quoted, and that the spreadsheet did not change any formats.
Exercise
A row in your insert file contains the value Smith, John in the Name column, and after loading, the following columns are shifted one position to the right. What is the cause, and how do you fix it?
Show answer
The comma inside the value was read as a column separator because the value was not quoted. Wrap the value in double quotes, as in "Smith, John", and reload the row. A double quote inside a quoted value must be written as two double quotes.