Sub topic 10
Working within API limits and handling large objects
This chapter assumes you can write a basic SOQL query, have run an export with Data Loader or the Salesforce CLI, and know what a Bulk API 2.0 query job is. It covers how Salesforce limits export traffic and how to keep large exports reliable.
Know the limits that affect exports
Salesforce caps how much work an org can do through its APIs. Three limits matter most for backups:
- Daily API request allocation. Each org gets a rolling 24-hour allowance of API calls. Its size depends on your edition and license count. Check your own numbers under Setup > System Overview or in the
limitsresource of the REST API. - Query timeouts and result size. A single synchronous query that scans too many rows can time out. This failure is common on objects with millions of records.
- Bulk API 2.0 limits. Bulk query jobs have their own daily caps on the data they return, and Salesforce can limit how many jobs run at once.
The exact figures change between releases, so confirm them in the current Salesforce limits documentation instead of hard-coding them in your plan.
Check your remaining allowance
Before a large run, read the org's limits. This command prints them as JSON:
sf limits api display --target-org my-prod-aliasLook at DailyApiRequests and DailyBulkV2QueryJobs, if your org's output lists them. Each shows a maximum and a remaining value. If the remaining value is low, delay the export. Backups that use up the allowance can break integrations that share the same org.
Choose the right tool for the volume
| Situation | Better choice |
|---|---|
| Under a few hundred thousand rows | `sf data query` or Data Loader |
| Millions of rows in one object | Bulk API 2.0 query job |
| Whole org, all objects, no custom code | Data Export Service |
Bulk API 2.0 works in the background. Salesforce splits the result into batches for you, so you create the job, poll its state, and download the results. This uses far fewer API calls than paging through rows.
Tactics for large objects
- Select only the fields you need. Fewer columns means smaller files and faster jobs. Avoid long text and rich text fields unless you truly need them.
- Filter by
LastModifiedDate. After one full export, run incremental exports that fetch only recent changes. This shrinks each run. - Split by range. If one query still fails, divide it by
CreatedDateranges, such as one query per year, and combine the files afterward. - Run off-peak. Schedule exports at night so they compete less with users and integrations.
- Export files separately. Attachments, Files, and other binary content are very large. Use the Data Export Service, which can include them, instead of querying them as rows.
A range-split query looks like this:
SELECT Id, Name, CreatedDate
FROM Account
WHERE CreatedDate >= 2025-01-01T00:00:00Z
AND CreatedDate < 2026-01-01T00:00:00Z
ORDER BY CreatedDateCommon errors
- Query timeout. The filter is not selective enough. Add a date range or use a Bulk API 2.0 job.
- Limit exceeded. The daily allowance is used up. Wait for the rolling window to free capacity or lower how often you export.
- Job stuck in
InProgress. Keep polling at a sensible interval, such as every 30 seconds, instead of retrying rapidly.
Exercise
An Account export with sf data query times out on an org with 8 million accounts. Name two changes you could make.
Show answer
Run the query as a Bulk API 2.0 job, which works in the background and returns the result in batches. Alternatively, split the query into CreatedDate ranges, or narrow it with a LastModifiedDate filter and fewer fields.