Sub topic 13
Verifying that an export is complete
This chapter assumes you can run SOQL queries, export records with Data Loader or the Salesforce CLI, and read CSV files. An export that finishes without an error can still be incomplete. Verification catches missing rows, truncated files, and broken relationships before you need the backup.
Why exports fall short
Common causes of an incomplete export:
- The query has a
WHEREclause that excludes records, such as a staleLastModifiedDatefilter. - The running user cannot see every record or field, because of sharing rules or field-level security.
- Deleted records were not requested (see the chapter on deleted records).
- A job was interrupted or hit an API limit, and the file stops early.
- Line breaks inside long text fields make a naive row count wrong.
Step 1: Compare record counts
Ask Salesforce how many records exist, then count what you exported. Use the same filter in both places.
SELECT COUNT() FROM AccountCount the CSV rows with a CSV-aware tool. The shell command wc -l counts lines, not records, so a text field with embedded line breaks inflates the total. This Python script counts records correctly:
import csv
import sys
csv.field_size_limit(sys.maxsize)
with open("accounts.csv", newline="", encoding="utf-8") as f:
reader = csv.reader(f)
next(reader) # skip the header row
rows = sum(1 for _ in reader)
print(f"Exported rows: {rows}")The two numbers should match. If records change while the export runs, a small difference is expected. Re-run the count query with a LastModifiedDate upper bound equal to the export start time to get a fair comparison.
Step 2: Check Ids and duplicates
Every row needs a unique, 15- or 18-character Id. Check for blank or repeated values:
import csv
seen = set()
problems = 0
with open("accounts.csv", newline="", encoding="utf-8") as f:
for row in csv.DictReader(f):
record_id = row["Id"]
if not record_id or record_id in seen:
problems += 1
seen.add(record_id)
print(f"Rows with a blank or duplicate Id: {problems}")Step 3: Check relationship Ids
A backup is only useful for restore if lookups still point at real records. For each child file, confirm that every non-blank foreign key, such as AccountId in Contact, appears as an Id in the parent file. Rows that fail this check are orphans. They usually mean the parent object was exported at a different time or with a narrower filter.
Step 4: Record the result
Write the object name, export time, expected count, actual count, and pass or fail to a log file. A log turns verification into evidence, and it lets you spot a trend, such as an object that loses rows each week.
Data Export Service files
The Data Export Service produces a set of ZIP files with one CSV per object. Open the ZIP files, confirm that each object you expect is present, and run the same count comparison on the most important objects. Download links expire after a few days, so verify promptly.
Exercise
A Contact export has 50,000 rows by CSV-aware count, and SELECT COUNT() FROM Contact returns 50,000. Name two more checks you should run before you trust the file.
Show answer
Check that every Id is unique and non-blank, and check that every non-blank AccountId appears as an Id in the Account export. You should also spot-check some records, because hidden fields export as empty columns without any error.