NexBlazers Logo
NexBlazers Learn • Build • Grow
Architecture & Apex

From 100K to Millions: Architecting Documents at Scale in Salesforce

Written by NexBlazers Architecture Team November 19, 2026 16 min read Interactive

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.

30M
max files per org (Enterprise, Unlimited)
200K
file versions per 24 hours, by default
2 GB
max per file via REST multipart
6 MB
synchronous Apex heap (12 MB async)
Try it

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.

1,000,000

Range from 100 thousand to 10 million documents.

Daily version limit
Raised via a Support case; 500K is the ceiling.
File storage needed
1.8 TB
Initial load
6 days
at the daily version limit
Of 30M file cap
3%
Enterprise / Unlimited

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

LimitValueWhy an architect cares
Max files (ContentDocuments)30,000,000Enterprise and Unlimited. A hard ceiling for "keep everything forever".
Files and versions per 24 hours200,000 default, up to 500,000Sets your migration timeline. Developer and trial orgs get 2,500.
Max file size by channel2 GB REST · 38 MB SOAP · 10 MB Bulk APIYour loader choice depends on your largest file, not your average one.
Content deliveries per 24 hours50 GB · 50,000 viewsPublic links at scale need a different delivery path.
Apex heap6 MB sync · 12 MB asyncBinaries 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 VersionData
Architecture Note: Decide where the binary lives and where the metadata lives as two separate decisions. Salesforce is excellent at metadata: sharing, reporting, Flow, search, Experience Cloud. At millions of documents, the binaries often belong in storage built for them, with Salesforce holding the record that points to them.
Decision helper

The Pattern Picker

Answer six questions about your documents. Get the architecture pattern that fits, with its trade-offs.

Question 1 of 6

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 FirstPublishLocationId to 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.
Go deeper

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.

  1. 1LWC asks Apex for an upload link
  2. 2Apex checks access, calls a signing service via Named Credential
  3. 3Browser uploads directly with the short-lived link
  4. 4Apex saves the key, size and checksum on a Salesforce record
Use it when
  • • Volume is in the millions or files are large (video, scans, CAD)
  • • Other systems need the same documents
  • • Storage cost has to stay predictable
Watch out for
  • • 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.

Interview-ready

Predict the Outcome

Six scenarios from real document-heavy orgs.

Question 1 of 6 Score: 0

Cheat sheet: architect's checklist

If you have…Lean towardsFirst thing to check
Under 1M active docs, used inside SalesforceNative FilesStorage forecast for 3 years
Docs already managed in Microsoft 365 or GoogleFiles ConnectReference vs Copy mode, and user access to the source
Millions of docs, mostly cold after 90 daysHybrid, tieredRetention policy and verified-delete process
5M+ docs, multiple consuming systemsExternal storage + registryNamed Credentials, unique keys and signed-URL expiry
An external system already indexes the documentsRegistry via external objectsSalesforce Connect licence and callout volume
Most documents are low-value or transientCritical-onlyAn agreed classification and retention matrix
Any migration over 200K filesPhased loadDaily 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.

Keep learning

Official Resources

Straight from Salesforce: the docs this article is based on.

Planning a document-heavy Salesforce rollout or migration?

Book a session with our architects to size storage, pick the pattern and plan the load.

Book Architecture Review