Sub topic 4
Exporting reports for small, targeted extracts
This chapter assumes you can build a basic report in Lightning Experience, you know what a report type is, and you have read the earlier chapter on choosing an export method. Reports suit small, ad hoc extracts. They are a poor fit for a full backup, and this chapter explains why.
What a report export is good for
A report export saves what a report shows as a file. Use one when you need a small, specific slice of data and you want to define it with the report builder instead of writing SOQL. Typical cases:
- An administrator needs the open opportunities for one region as a spreadsheet.
- A team wants a snapshot of a filtered list before a bulk update.
- A business user needs an extract and has no access to Data Loader or the CLI.
Reports are the wrong tool when you need every record of an object, deleted records, or a repeatable job with a record count you can audit. Use the Data Export Service, Data Loader, the CLI, or the Bulk API for those.
Two export formats
When you export from the report run page, Salesforce offers two choices.
| Format | What you get | Typical file | Use it for |
|---|---|---|---|
| Formatted Report | Groupings, subtotals, and summaries as they appear on screen | `.xlsx` | Sharing a report with people |
| Details Only | A flat table of the detail rows, with no groupings or summaries | `.csv` or `.xls` | Data work, comparison, or reloading |
For backup-style extracts, choose Details Only and the CSV encoding. A flat file is easier to compare, load into a script, or diff against a later extract. A formatted export is built for people, so subtotals and merged cells get in the way of any tool that reads it.
Joined reports and some report types have export restrictions. If the Export button is missing or a format is not offered, check the report type and your permissions before assuming something is broken.
What controls whether you can export
Three things decide what ends up in the file.
- Permission. The user needs the Export Reports permission, which an administrator can grant through a profile or permission set. Without it, the Export button does not appear.
- Visibility. A report runs as the person viewing it, so it returns only the records that person can see through sharing rules and field-level security. An administrator with View All Data sees more than a sales user does. The same report can export different rows for different people.
- The report type. Only the fields and objects the report type exposes can be exported. Some fields you would expect may be missing, and a report type that joins objects may drop records that have no match, such as accounts with no opportunities.
The visibility rule is the main reason reports are unreliable as a backup. If the person who exports the data is not an administrator with full access, the file is silently incomplete, and nothing in it tells you so.
Making a report suitable for export
A few choices in the report builder make the export far more useful.
- Add the record Id. Include the Id column of the main object, for example
Account ID. Without it you cannot match exported rows back to records for an update or a restore. - Add the Id of parent records when you need to rebuild relationships. A name such as
Account Nameis not unique, so it cannot identify a parent reliably. - Use a tabular report when you want rows only. Summary and matrix reports are meant for aggregation, and in a Details Only export the groupings are dropped.
- Set a scope and filters to say exactly what the extract covers. Write a date range as an absolute filter, such as a fixed start date, when you want a repeatable extract. A relative filter such as
LAST 30 DAYSreturns different rows each day. - Check the row count on screen before exporting. The report run page shows the total, and you will use it later for verification.
Row limits and what happens at the edge
Reports are built for people to read, so they are limited in size. The report run page shows a limited number of rows, while an export file can hold more. Exports have their own row ceilings, and the formatted export has a lower ceiling than the details-only export. Spreadsheet applications also have their own maximum row count. The exact numbers depend on the edition and the release, so check the current Salesforce documentation instead of relying on a figure from memory.
The practical rule: if your extract is close to the tens of thousands of rows, move it to a query tool. The Reports REST API has a similar ceiling. A synchronous run returns only a limited number of detail rows, and it flags the result as incomplete with a allData value of false in the response when it cut the rows off.
Report extract or SOQL query?
Most report extracts can be written as a SOQL query. The report builder gives you filters and columns without any syntax. SOQL gives you control, repeatability, and the ability to run unattended. The report below and the query after it return the same rows.
A report on the Account object, with the filter "Last Modified Date is on or after 2026-01-01" and the columns Account ID, Account Name, Industry, and Owner ID, is equivalent to:
SELECT Id, Name, Industry, OwnerId
FROM Account
WHERE LastModifiedDate >= 2026-01-01T00:00:00Z
ORDER BY LastModifiedDateIf you find yourself exporting the same report every week, convert it into a query and schedule it with the CLI, as covered in the chapter on automation.
Checking the exported file
A report export is only as good as your check of it. Count the data rows in the CSV and compare them with the total on the report run page. Do not use wc -l for this, because a field with a line break inside it, such as a description, spans several lines in the file and inflates the count. A CSV parser counts records correctly.
import csv
import sys
path = sys.argv[1]
expected = int(sys.argv[2])
with open(path, newline="", encoding="utf-8-sig") as f:
reader = csv.reader(f)
header = next(reader)
rows = sum(1 for _ in reader)
print(f"Columns: {len(header)} Data rows: {rows} Expected: {expected}")
if rows != expected:
sys.exit("Row count does not match the report total")Run it as python check_export.py report.csv 1842, replacing the file name and the number with the values from your report. The utf-8-sig encoding strips the byte order mark that some exports add to the start of the file, so the first column name is read correctly.
Common errors
- No Export button. The user lacks the Export Reports permission, or the report type does not allow export.
- Fewer rows than expected. The running user cannot see all records, or an inner join in the report type excluded records with no related child.
- Names where Ids should be. The report has no Id columns, so the file cannot be matched back to records.
- Dates and numbers look wrong in a spreadsheet. The application reformatted the values on opening. Keep the original CSV as the record, and treat the spreadsheet as a view.
- Different rows on each run. A relative date filter changed the scope. Use fixed dates for a repeatable extract.
- Sensitive data left in the downloads folder. Exported files are plain text. The chapter on securing exported files covers storage and retention.
Exercise
A colleague exports a tabular report of all accounts as Details Only and gets 4,200 rows. You run the same report as an administrator and the run page shows 5,150 records. Give two likely causes and one step to confirm the cause.
Show answer
Likely causes: your colleague's sharing access hides some accounts from them, so the report returned fewer rows, or the export was cut off at a row limit. To confirm, run the report as your colleague, or compare the colleague's on-screen total with their file. If their screen shows 4,200, the cause is visibility. If their screen shows 5,150 and the file has 4,200, the export was truncated, and you should move the extract to Data Loader or a SOQL query.
Exercise
Name two fields you should add to a report before exporting it, if you may need to match the rows back to Salesforce records later, and explain why a name column is not enough.
Show answer
Add the record's own Id, such as Account ID, and the Id of any parent record you need to rebuild relationships, such as the parent Account ID on a contact report. Names are not unique and can change, so they cannot identify a record reliably.