Sub topic 3
Scheduling a full export with the Data Export Service
The Data Export Service is the built-in way to get a complete copy of your org's data without writing a query. You configure it in Setup, Salesforce builds a set of CSV files, and you download them from a link. This chapter covers how to configure it, what the output contains, and what it cannot do.
This chapter assumes you can open Setup as an administrator, you know what an object, record, and field are, and you can read a CSV file. Command-line steps use Python 3.
What the service does
The service writes the records of your objects into CSV files, one file per object. It packages them into one or more ZIP archives. It runs on Salesforce's servers, so it doesn't use your API request allocation and needs no client tools.
It is a good fit for a baseline copy of everything. It is a poor fit when you need a specific subset, a custom file layout, or a backup more often than weekly. The next chapters cover queries and tools for those cases.
The service exports data only. It does not export metadata such as Apex classes, flows, page layouts, or object definitions. It also does not give you a restore tool. You get CSV files and must load them back yourself.
Scheduled and on-demand exports
There are two ways to start an export. Both are under Setup, in Data, then Data Export.
- Export Now queues a one-off export immediately. Use it before a risky change such as a large data load or a release.
- Schedule Export creates a recurring export with a start date, an end date, and a frequency.
Allowed frequency depends on your edition. Enterprise, Unlimited, Performance, and Developer editions can usually choose weekly or monthly. Some other editions are limited to monthly. Salesforce also enforces a minimum gap between exports, so you can't run Export Now repeatedly in one day. Check the Data Export page in your org for the options it offers, because limits change between releases.
The scheduled export starts at about the time you choose, but it is queued. A large org can wait a while before the file is ready, so don't depend on an exact completion time.
Configuring an export
Open the Data Export page and choose Schedule Export. You will see these settings:
| Setting | What it controls | Practical advice |
|---|---|---|
| Encoding | Character set of the CSV files | Pick UTF-8 unless a downstream tool requires something else. |
| Include images, documents, and attachments | Adds legacy file records | Turn on if you still use Documents or Attachments. |
| Include Salesforce Files and Salesforce CRM Content document versions | Adds the file contents of modern Files | Turn on if users store files. Expect much larger exports. |
| Avoid Using Horizontal Scroll Bars | Replaces carriage returns and line feeds in text with spaces | Leave off for a faithful backup. Turn on only if a tool breaks on multi-line values. |
| Include all data | Exports every supported object | Best default for a backup. |
| Exported Data (selected objects) | Exports only the objects you tick | Use to reduce size or exclude sensitive objects. |
The "Include all data" option is the safest choice for a backup. If you select individual objects, a new custom object added later is not exported until someone ticks it. That is a silent gap.
Newlines inside text fields are preserved in the CSV, inside quoted values, unless you turn on the option that replaces them. This matters for verification later.
The export lifecycle
After you save a schedule, the service follows the same sequence each time.
Three details from this sequence cause most of the problems:
- The email goes to the user who set up the export. If that person leaves, or the address is a personal mailbox, the notice is lost.
- You must be signed in to download. The link is not a public URL.
- The files expire. Salesforce keeps them for 48 hours, so a missed email can mean a missed backup.
Reading the output
A large export is split into several ZIP files. Each is limited in size, so you must download all of them. A single object file is not split across ZIPs, but different objects can be in different ZIPs. A missing ZIP means missing objects.
Inside the ZIPs, each object is a CSV named after the object's API name, such as Account.csv or Opportunity.csv. Each file has a header row of field names, then one row per record. Lookup fields hold the Id of the related record, not its name. Relationships are therefore preserved as Ids, which is what you need for a restore (see the later chapter on restore order).
Some things you should expect to find missing or different:
- Records in the Recycle Bin are not included.
- Some objects and field types are not exportable, such as certain system-managed objects and fields you cannot read.
- Metadata is absent. Keep a separate metadata backup.
- Files exported with "Include Salesforce Files" arrive as binary content alongside the CSV, and the size can dominate the download.
A quick completeness check
Before filing an export away, count the rows per CSV and compare them with a count in the org. Using wc -l is wrong here, because a text field with line breaks spans several physical lines. Use a CSV parser instead. This script reads each CSV inside one ZIP and prints the record count.
import csv
import io
import sys
import zipfile
csv.field_size_limit(sys.maxsize)
zip_path = sys.argv[1]
with zipfile.ZipFile(zip_path) as archive:
for name in sorted(archive.namelist()):
if not name.lower().endswith(".csv"):
continue
with archive.open(name) as raw:
text = io.TextIOWrapper(raw, encoding="utf-8", newline="")
rows = sum(1 for _ in csv.reader(text)) - 1 # minus the header
print(f"{name}\t{rows}")Run it as python count_rows.py WE_00D000000000000_1.ZIP, once for each ZIP. If you chose an encoding other than UTF-8, change the encoding argument to match. Then compare a few objects with SELECT COUNT() FROM Account in the Developer Console or the CLI. The two numbers should agree, apart from records created or deleted since the export began.
Common errors
- No email arrives. The export may still be queued, the notification address may be wrong, or the message may be in spam. Check the Data Export page, which lists available files.
- The link has expired. Files older than 48 hours are gone. Run Export Now if your edition allows it, or wait for the next scheduled run.
- An object is missing. You may have selected objects by hand instead of "Include all data," or the object is not exportable. Compare the CSV list with your object list.
- Row counts differ by a small number. Data changed while the export ran. Compare counts using
CreatedDateandLastModifiedDateboundaries if you need to resolve it. - The schedule stopped. The end date you set on the schedule has passed. Set it far in the future and review it each quarter.
Exercise
Your team schedules a weekly export with "Include all data". Three weeks later an auditor asks for last Tuesday's export, but nobody can find it. What went wrong, and what two changes would prevent it?
Show answer
Salesforce deletes the export files 48 hours after they are built, and it does not keep copies, so the export was never saved unless someone downloaded it. Prevent it by (1) naming an owner, and a shared notification address, responsible for downloading every ZIP file after each run, and (2) moving the files into secured storage with a defined retention period, and checking row counts when you store them.