Sub topic 12
Safe import practices
This chapter covers the habits that keep an import from damaging your data. It assumes you can already run an import with the Data Import Wizard or Data Loader, read success and error files, and prepare a CSV file. The goal here is to make failures cheap: you catch them early, you can undo them, and you can explain what happened.
Why imports need extra care
An import is a bulk write. One wrong mapping or one bad filter can change thousands of records in a few minutes. Salesforce has no general "undo" for a data load. A deleted record can be restored from the Recycle Bin for a limited time, but an overwritten field value is gone unless you saved it somewhere else.
Most import incidents come from a small set of causes:
- Loading into production before the file was tested.
- Updating or deleting records with no backup of the current values.
- Mapping a column to the wrong field, which looks fine until someone reads the data.
- Triggering automation (flows, triggers, emails) that nobody planned for.
- Creating duplicates because matching was off or the wrong operation was chosen.
- Running a large job with the wrong user, so records get the wrong owner or audit trail.
The sections below address each one.
The safe import workflow
Follow the same sequence for every non-trivial import.
Test in a sandbox first
A sandbox is a copy of your org's configuration, and depending on its type, some or all of its data. Run the real file there before you touch production. A sandbox test shows you three things that a spreadsheet check cannot:
- Validation rules, required fields, and picklist restrictions that reject rows.
- Automation side effects, such as flows that update related records or send email.
- Rough timing, which helps you plan a production window.
Two cautions apply. First, a sandbox may not contain the same data as production, so lookups to existing records can fail there for reasons that will not occur in production. Record IDs also differ between orgs, so a file that uses Salesforce IDs must be rebuilt for each org. External IDs avoid this problem, which is one reason to prefer them for relationships. Second, check whether the sandbox can send real email. Sandboxes default to restricting email deliverability to system email, but confirm that setting before loading records that fire email alerts.
If you have no sandbox, a Developer Edition org is a reasonable place to test the file structure, though it will not mirror your production automation.
Back up before you change anything
Insert operations add records, so the main recovery path is deleting what you added. Update, upsert, and delete operations change or remove existing data, so you need a copy of the "before" state.
Use a Data Loader export to capture the records you are about to change. The query should include the Id and every field you will modify:
SELECT Id, Name, Phone, Industry FROM Account WHERE Industry = 'Energy'Save the export with a date in the file name, such as account_backup_2026-11-30.csv. If the update goes wrong, this file is already in the right shape to be reloaded as an update, because it has an Id column and the field values you want to restore.
The same export also gives you the real record IDs for your update file. The update file below uses placeholder IDs, which you must replace with IDs from an export:
Id,Phone,Industry
001XXXXXXXXXXXXXXX,555-0199,Energy
001YYYYYYYYYYYYYYY,555-0198,RetailBack up more than the fields you change when relationships or automation matter. For example, if an update might fire a flow that modifies related records, export those related records too. For a large or critical load, the Data Export service in Setup (Weekly or Monthly Export) provides a full org backup, but it is scheduled and is not a substitute for a targeted export taken right before your job.
Validate the file before loading
Catch problems in the file, not in the error log. Before every load:
- Confirm the header row matches the fields you intend to map, and that there is exactly one header row.
- Check for blank rows at the end of the file, which spreadsheets often leave behind.
- Look for values that spreadsheets silently change: leading zeros dropped from ZIP codes, long numbers turned into scientific notation, and dates reformatted by locale.
- Verify picklist values against the active values on the field. A value that is not in the list is rejected for restricted picklists.
- Confirm required fields are populated on every row.
- Check text lengths against field limits.
- Remove duplicates inside the file itself. Salesforce checks a file against existing data, but two identical rows in the same file can both be inserted.
- Save as CSV with UTF-8 encoding so names with accents or non-Latin characters load correctly.
Sorting and filtering in a spreadsheet will show you empty cells and odd values quickly. For a final check, open the saved CSV in a plain text editor, because that is what the tool will actually read.
Load a small batch first
After the sandbox test, run a pilot in production with a small slice of the real file, for example 10 to 50 rows chosen to include your edge cases. Then open the records in Salesforce and check them by eye:
- Are the field values what you expect?
- Is the owner correct?
- Do lookup fields point to the right records?
- Did any automation run, and was its result correct?
Only then load the remainder. When you load the remainder, remove the rows you already inserted from the file. Otherwise an insert will create them a second time. An upsert with an external ID is safer for staged loads because re-running it updates the existing rows instead of duplicating them.
Choose the operation that limits damage
The choice of operation controls how bad a mistake can be.
| Situation | Safer choice | Risk to watch |
|---|---|---|
| Adding new records that may already exist | Upsert on an external ID, or wizard matching | Plain insert creates duplicates |
| Changing fields on known records | Update with IDs taken from a fresh export | Stale IDs update the wrong records |
| Removing records | Export first, then delete | Delete is hard to undo beyond the Recycle Bin |
| Removing records permanently | Avoid hard delete unless required | Hard delete skips the Recycle Bin |
| Reloading a failed batch | Load only the error file after fixing it | Reloading the whole file repeats successes |
Be careful with blank cells in updates. By default, Data Loader treats an empty cell as "no change" for that field. A setting named "Insert null values" changes this so that empty cells clear the field. Leave it off unless you intend to erase data, and when you do turn it on, check the backup first.
Control side effects
Automation runs during imports just as it does for manual edits. Before a large load, list what is attached to the object:
- Validation rules that may reject valid historical data. Do not turn them off casually. If you must bypass one, use a documented, temporary approach such as a custom permission or a field that the rule checks, and restore it afterward.
- Flows, Process Builder processes, and Apex triggers that create tasks, update related records, or send email.
- Assignment rules and auto-response rules. The Data Import Wizard lets you choose whether to trigger workflow rules and processes; Data Loader runs them according to the org's configuration.
- Duplicate rules, which can block rows or flag them depending on how they are set.
Also decide record ownership on purpose. If the file has no owner column, records belong to the user who runs the import. Running a migration as a named integration user, rather than a person, gives a clear audit trail and avoids sending notifications to someone's inbox.
Loads also use up daily API request allowances and can lock records. Large updates to child records with the same parent can cause lock errors, because the parent row is locked while children update. Sorting the file by parent ID, or lowering the batch size, reduces these errors.
Verify after the load
A load that reports success has only told you the rows were accepted. Verify the result:
- Compare counts. Rows in the file should equal the rows in the success file plus the rows in the error file.
- Query the loaded data with SOQL or a report and compare totals, such as the number of Accounts per industry, against the source file.
- Spot-check records, including edge cases like special characters and empty optional fields.
- Confirm that relationships resolved. A report that groups Contacts by Account will show orphans quickly.
- Check the system for unexpected activity, such as emails sent or tasks created.
Keep the success and error files with the source CSV and the backup. If you need to roll back, the success file lists the IDs created by an insert, so you can use it as the input for a delete. For an update, reload the pre-change backup as an update.
Document and archive
Write a short record of each load: who ran it, when, which org, which operation, which file, and the counts. Store the source file, backup, success file, and error file together. Months later, this record answers "where did these records come from?" without guesswork.
For loads that recur, move the process into a repeatable form, for example saved mapping files (.sdl) and command-line runs, so that the tested process is the one that runs each time.
Common mistakes
- Testing with a different file than the one you load. If you edit the file after the test, the test no longer proves anything. Test the final file.
- Using IDs from the wrong org. IDs from a sandbox export do not exist in production.
- Skipping the backup because the change is "small". Small changes with a bad filter affect many records.
- Treating the success file as proof of correctness. It proves acceptance, not accuracy.
- Re-running the whole file after a partial failure. Load only the corrected error rows.
Exercise
You must change the Industry on about 4,000 production Accounts, using a CSV prepared by a colleague. List the steps you would take, in order, before and after the production load.
Show answer
1) Export the affected Accounts (Id, Name, Industry, and any other field being changed) with Data Loader and save it with a date. 2) Check the CSV: one header row, no blank rows, picklist values match active Industry values, IDs belong to the production org, UTF-8 encoding. 3) Review validation rules, flows, and triggers on Account. 4) Run the same final file in a sandbox, using IDs from a sandbox export, and review results. 5) In production, update a pilot of 10 to 50 rows and inspect the records. 6) Run the remaining rows. 7) Check that success rows plus error rows equals the file's row count, then query or report on Industry counts. 8) Fix and reload only the error rows. 9) Archive the file, backup, success file, and error file. If something is wrong, reload the backup export as an update.
Exercise
A Data Loader update file has some blank Phone cells. You want those blank cells to leave the existing phone numbers alone. What do you check, and why?
Show answer
Check that "Insert null values" is turned off in Data Loader settings. With it off, empty cells are ignored and existing values stay. With it on, empty cells erase the field value, so you would lose phone numbers that you could only recover from a backup export.
Exercise
Why is an upsert on an external ID safer than a plain insert when you load a large file in several stages?
Show answer
If a stage is repeated, an upsert matches rows on the external ID and updates the existing records instead of creating new ones. A plain insert always creates a new record, so repeating a stage produces duplicates.