Sub topic 2
Exporting Records with Data Loader
Assume you know Salesforce objects, records, and fields, can read CSV files, and can run terminal commands. Data Loader is a desktop tool for moving Salesforce records between an org and files. Use Export for current records. Use Export All when you also need records in the Recycle Bin and archived activities.
Exporting records and deleted records
In Data Loader:
- Choose Export or Export All.
- Log in to the org.
- Select an object, such as Account.
- Select the fields to export.
- Optionally enter a SOQL
WHEREclause. - Choose a CSV destination and run the export.
Export All includes soft-deleted records that Salesforce still retains. It does not recover records that were permanently deleted. Keep the Id field in every export so that you can identify records and preserve relationships.
Command-line and large-volume exports
The Salesforce CLI is useful for repeatable exports:
sf data query \
--query "SELECT Id, Name, Industry FROM Account" \
--result-format csv \
--target-org my-prod-alias > accounts.csvFor large objects, use a Bulk API 2.0 query job instead of downloading a large result interactively. Create the job, poll until its state is JobComplete, and then download the results. Use the queryAll operation when the export must include deleted and archived records.
API limits restrict request counts, query processing, and result sizes. Export in object-specific batches, filter by LastModifiedDate for incremental backups, and record failed jobs. Test queries in a sandbox before scheduling them.
Backing up metadata
Records are data. Custom fields, flows, Apex classes, and object definitions are metadata, so back them up separately with a manifest:
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>*</members>
<name>CustomObject</name>
</types>
<types>
<members>*</members>
<name>Flow</name>
</types>
<version>60.0</version>
</Package>Retrieve the manifest into a Salesforce DX project and commit the files to version control.
Preserving relationships and restore order
Export relationship fields such as AccountId, ContactId, and OwnerId. Restore referenced records before dependent records. If Salesforce assigns new IDs, create an old-to-new ID mapping and use it while loading child CSV files.
Exercise
Which Data Loader option includes records still in the Recycle Bin?
Show answer
Export All. Permanently deleted records are not included.