Sub topic 6
Exporting Records with Data Loader
This chapter assumes you can write a basic SOQL query and have a sandbox or Developer Edition org with an administrator profile. Data Loader is Salesforce's desktop tool for bulk import and export. For backups, you use its Export and Export All actions to write query results to CSV files.
How an export works
Data Loader takes a SOQL query, runs it against the org, and writes each returned row to a CSV file. You choose the object, the fields, and an optional filter. The result is one flat file per query.
The steps in the wizard are:
- Log in with OAuth. Use a sandbox login first.
- Choose Export.
- Select the object, for example Account, and a destination CSV file.
- Build the query. Pick fields and add a
WHEREclause if you want one. - Select Finish, then confirm.
Data Loader then reports how many rows it wrote. Keep that number, because you will compare it with a count query later.
Writing the query
Select explicit fields instead of every field. Filtering on LastModifiedDate gives you incremental exports, where each run captures only what changed since the last one.
SELECT Id, Name, Industry, OwnerId, CreatedDate, LastModifiedDate
FROM Account
WHERE LastModifiedDate >= 2026-01-01T00:00:00Z
ORDER BY LastModifiedDateAlways include Id. It is the key you need when you restore data or relate one file to another.
Parent fields and child records
Data Loader can export parent fields reached through a relationship, such as Account.Name on a Contact. It cannot export subquery results, because a CSV row has no place to hold a list of child rows.
SELECT Id, FirstName, LastName, Account.Name,
(SELECT Id, Subject FROM Tasks)
FROM Contact
LIMIT 100The query above is valid SOQL, but Data Loader will not export it as written. Remove the Tasks subquery and export Task with its own query. Each Task row has a WhoId that points back to the Contact.
Common errors
- Missing records. Export skips deleted records. Use Export All to include records in the Recycle Bin. The next chapter covers deleted data in more detail.
- Subquery failure. Data Loader rejects queries that contain a child subquery. Split them into separate exports.
- Truncated or garbled text. Open the CSV in a text editor, not a spreadsheet. Spreadsheets can change dates, drop leading zeros, and break long text fields. Set the file encoding to UTF-8 in Data Loader settings.
- Field not visible. Data Loader respects field-level security. A field the login user cannot read is missing from the field list, so use a user with access to every field you need.
- Wrong row count. Check that the query has no unintended
WHEREclause orLIMIT.
Checking the result
After each export, compare the row count with the org's record count.
SELECT COUNT() FROM AccountIf the CSV has 10,000 data rows and the query returns 10,000, the export is complete for that object. The header row does not count. If you used a WHERE clause, put the same filter in the count query.
Exercise
You export Contacts with Data Loader and want each Contact's open Tasks in the backup. The query with a Tasks subquery fails. What do you do, and which field links the two files?
Show answer
Export Contact and Task with separate queries. Include Id in the Contact query and WhoId in the Task query. WhoId holds the Id of the related Contact, so you can join the two files or restore them in order.