From 100K to Millions: Architecting Documents at Scale in Salesforce
Your service team uploads 4,000 PDFs a day. It works fine in year one. By year three you are buying storage every quarter, the migration from the old ECM has been running for two weeks, and someone's Apex just failed with heap size too large. Documents don't break Salesforce at 100K. They break the plan that assumed 100K.
This post looks at the problem the way an architect does: separate where the binary lives from where the metadata lives, then design for the platform's real limits. You'll size your own volume in the Scale Planner and get a recommended pattern from the Pattern Picker. Then you'll explore three strategies in depth: external storage, Salesforce as the document registry, and keeping only critical documents in Salesforce. A triage game and a scenario quiz close it out.
The Scale Planner
Enter your volumes. See the storage you need, how long the initial load takes and where you hit the platform's limits.
Range from 100 thousand to 10 million documents.
Planning estimates only. Storage is counted per version you keep, and your contract may include more storage than the base allocation.
1. Know the three objects before you scale them
Every Salesforce File is three objects working together. ContentDocument is the file itself. ContentVersion holds each version's binary. ContentDocumentLink connects a file to the records, users, groups and libraries it's shared with.
Two rules shape everything at volume. First, a ContentVersion can't be updated. New content always means inserting a new version, and every version you keep takes storage. Second, queries on ContentDocumentLink must filter on Id, ContentDocumentId or LinkedEntityId. From API version 59.0, the Query All Files permission removes that requirement, but it needs View All Data.
// Selective: start from the business record, not from the file
List<ContentDocumentLink> links = [
SELECT ContentDocumentId, ContentDocument.Title, ContentDocument.ContentSize
FROM ContentDocumentLink
WHERE LinkedEntityId = :caseId
];2. The limits that bite between 100K and millions
| Limit | Value | Why an architect cares |
|---|---|---|
| Max files (ContentDocuments) | 30,000,000 | Enterprise and Unlimited. A hard ceiling for "keep everything forever". |
| Files and versions per 24 hours | 200,000 default, up to 500,000 | Sets your migration timeline. Developer and trial orgs get 2,500. |
| Max file size by channel | 2 GB REST · 38 MB SOAP · 10 MB Bulk API | Your loader choice depends on your largest file, not your average one. |
| Content deliveries per 24 hours | 50 GB · 50,000 views | Public links at scale need a different delivery path. |
| Apex heap | 6 MB sync · 12 MB async | Binaries don't belong in Apex memory. |
Watch these numbers continuously, not just at go-live. The REST Limits resource returns ContentPublicationLimit and MaxContentDocumentsLimit, so your monitoring can alert you before a load stalls.
3. Never push binaries through Apex
Reading VersionData into a Blob, base64-encoding it and posting it somewhere works in a sandbox with a 2 MB test PDF. In production, a 15 MB scan blows past the heap limit, and you can't catch that exception. Move bytes with APIs built for bytes. Upload a ContentVersion with a multipart REST request (up to 2 GB per file). Or have the browser upload straight to external storage with a short-lived signed URL, and let Apex handle only the metadata.
curl https://MyDomainName.my.salesforce.com/services/data/v67.0/sobjects/ContentVersion \
-H "Authorization: Bearer $TOKEN" \
-H 'Content-Type: multipart/form-data; boundary="boundary_string"' \
--data-binary @NewContentVersion.json
# Part 1: JSON (Title, PathOnClient, FirstPublishLocationId)
# Part 2: the binary, named VersionDataThe Pattern Picker
Answer six questions about your documents. Get the architecture pattern that fits, with its trade-offs.
4. The five patterns, in one line each
- ANative Salesforce Files. Binaries live in Salesforce, with full previews, sharing, search and Experience Cloud access. Comfortable into the hundreds of thousands. Watch storage cost and the daily version limit.
- BFiles Connect. Files stay in SharePoint Online, OneDrive, Google Drive or Box and appear inside Salesforce. In Reference mode nothing is copied and access follows the external system. Copy mode stores a copy in Salesforce, which suits sharing with customers and partners.
- CHybrid, tiered by age. Recent, active documents are native Files. A scheduled job moves documents past their active window to external storage, keeps a metadata record with a link, and deletes the Salesforce copy only after it has verified the external one.
- DExternal storage + Salesforce registry. Binaries live in object storage or an enterprise content system. Salesforce holds a lightweight document record (key, size, checksum, retention date, parent lookup). The UI gets short-lived links through a Named Credential callout.
- ECritical-only in Salesforce. Classify every document when it arrives. Only business-critical ones (signed contracts, compliance evidence) stay as native Files. Working copies go to external storage, and transient files are never kept.
5. Migrating millions: do the math first
At the default limit, Salesforce accepts 200,000 new files and versions in a rolling 24-hour window. That makes 1.2 million documents at least six days of loading, before retries and before your users' own uploads, which share the same limit. If the timeline matters, raise the limit with Salesforce Support before cutover weekend, not during it.
- Pick the loader by your largest file. Bulk API can load binaries in zip batches, but caps each file at 10 MB. REST multipart handles files up to 2 GB.
- Make reruns safe. Put an external ID custom field on ContentVersion so a restarted job can skip what's already loaded.
- Link files where they belong. Set
FirstPublishLocationIdto the business record (Case, Claim, Account) so the link is created with the file. Don't park millions of files on one "holder" record. - Load in waves and reconcile counts and checksums after each wave, not at the end.
Three Strategies, Up Close
Pick a strategy to see how it works, when to use it, what goes wrong, and a starting point for the build.
The file goes straight from the user's browser to object storage (Amazon S3, Azure Blob, Google Cloud Storage). Salesforce never touches the bytes. It only decides who may upload or download, and records what was stored.
- 1LWC asks Apex for an upload link
- 2Apex checks access, calls a signing service via Named Credential
- 3Browser uploads directly with the short-lived link
- 4Apex saves the key, size and checksum on a Salesforce record
- • Volume is in the millions or files are large (video, scans, CAD)
- • Other systems need the same documents
- • Storage cost has to stay predictable
- • Same key overwrites. S3 replaces an existing object uploaded to the same key, so generate unique keys (record Id + UUID).
- • Links are bearer tokens. A presigned URL works for anyone who has it until it expires. Keep expiry to minutes.
- • Verify integrity. Send an MD5 digest with the upload and store it on the record.
A presigned URL gives time-limited access to one object without sharing storage credentials. Keep the signing secret out of Salesforce: let a small signing service (a serverless function, say) hold it, and reach that service through a named credential, which stores the endpoint and its authentication in one definition.
Predict the Outcome
Six scenarios from real document-heavy orgs.
Cheat sheet: architect's checklist
| If you have… | Lean towards | First thing to check |
|---|---|---|
| Under 1M active docs, used inside Salesforce | Native Files | Storage forecast for 3 years |
| Docs already managed in Microsoft 365 or Google | Files Connect | Reference vs Copy mode, and user access to the source |
| Millions of docs, mostly cold after 90 days | Hybrid, tiered | Retention policy and verified-delete process |
| 5M+ docs, multiple consuming systems | External storage + registry | Named Credentials, unique keys and signed-URL expiry |
| An external system already indexes the documents | Registry via external objects | Salesforce Connect licence and callout volume |
| Most documents are low-value or transient | Critical-only | An agreed classification and retention matrix |
| Any migration over 200K files | Phased load | Daily version limit and a Support case |
Limits checked against Salesforce Help and Developer documentation in November 2026. Allocations can change by release and contract, so confirm yours in Setup → Company Information and Storage Usage.
Official Resources
Straight from Salesforce: the docs this article is based on.
Trailhead
- Large Data Volumes Module · plan for and work with LDV
- Manage Data at Scale with Salesforce Scalability with Salesforce module
- Mitigate Failing Data Loads Org scaling anti-patterns
- Protect Secrets Using Platform Features Named credentials for callouts
- Work with Notes and Files Lightning Experience productivity
Developer Docs
- ContentVersion Object Reference
- ContentDocumentLink Object Reference
- Insert or Update Blob Data REST API Developer Guide
- Load Binary Attachments Bulk API Developer Guide
- External Objects Object Reference · Salesforce Connect
- Get Started with Named Credentials Named Credentials Developer Guide
- Limits resource REST API Developer Guide
- Execution Governors and Limits Apex Developer Guide
Planning a document-heavy Salesforce rollout or migration?
Book a session with our architects to size storage, pick the pattern and plan the load.