Generating salesforce file attachment test data is not the same exercise as loading Accounts or Opportunities. ContentVersion stores file content as a base64-encoded blob, not a plain field value, and that single difference breaks most of the load scripts teams reuse from standard object testing. Get the encoding, the linking, and the sizing wrong, and your job either fails outright or produces files that no test actually exercises.

The object model itself adds friction. A file in Salesforce is really three records working together: ContentVersion holds the actual bytes, ContentDocument represents the file as a whole, and ContentDocumentLink connects that file to whatever record needs to see it. Test data generators that only know how to insert rows into one object at a time stumble here, because the relationship chain has to be built in a specific order with specific fields populated correctly.

Why ContentVersion Breaks Standard Bulk API Patterns

Most objects you load through Bulk API v2 have fields that map cleanly to CSV or JSON values: text, numbers, dates, lookups. ContentVersion has VersionData, and VersionData has to hold a base64-encoded representation of the file bytes, embedded directly in the row. There is no separate binary attachment channel in Bulk API v2 the way there was in SOAP-based batch uploads for Attachment records in Bulk API 1.0.

That means every file you want to test with gets inflated by roughly 33% once encoded, and that inflated string lives inside a single CSV cell. A 2MB PDF becomes a 2.7MB string sitting in one row of your job data file. Multiply that by a few thousand rows meant to simulate a busy Files-enabled object, and you can hit the 150MB per-batch ingest limit a lot faster than you would with ordinary record data.

I have seen teams try to work around this by shrinking every test file down to a few bytes of placeholder text. That gets the job to succeed, but it also means nothing in the test actually resembles what a user will upload. A one-line text string does not trigger the same rendering logic, the same file preview behavior, or the same storage calculations as a real 500KB image. Sizing matters, and we will come back to it.

The ContentVersion to ContentDocumentLink Chain

Inserting ContentVersion on its own gives you a file that exists but is attached to nothing. Salesforce auto-creates the parent ContentDocument for you, but linking that document to a Case, an Opportunity, or a custom object record is a separate step through ContentDocumentLink, which needs ContentDocumentId, LinkedEntityId, ShareType, and Visibility.

There is a shortcut worth knowing: setting FirstPublishLocationId on the ContentVersion record at insert time causes Salesforce to auto-generate the ContentDocumentLink for you, skipping the manual second insert. This works for most standard and custom objects, with the caveat that the target object has to support Chatter feed tracking or file attachments in the first place. For bulk test data generation, this single field removes an entire extra job from your pipeline.

The tradeoff is control. FirstPublishLocationId gives you one link per file, with a default ShareType. If your test scenario needs a file shared across multiple records, or needs a specific Visibility setting like InternalUsers versus AllUsers, you still have to insert ContentDocumentLink rows directly after the ContentVersion job completes and you have captured the resulting ContentDocumentId values.

ApproachWhen to use itLimitation
FirstPublishLocationId on insertOne file, one parent record, default sharingNo control over ShareType or multiple links
Separate ContentDocumentLink insertShared files, custom Visibility, multiple parentsRequires a second job and the ContentDocumentId mapping

Either path requires a lookup step between jobs: you need the ContentDocumentId generated by the ContentVersion insert before you can build the ContentDocumentLink rows. SproutEzee handles this by querying the result file from the first Bulk API v2 job and feeding the IDs straight into the second, so the dependency resolves without manual CSV wrangling.

Sizing Fake Files for Realistic Test Coverage

A test suite that only ever uploads 10KB text files will never catch the bug where a 15MB PDF times out a Visualforce preview page, or the one where an image compression trigger chokes on a file over 5MB. Realistic salesforce file attachment test data needs a distribution of sizes and types, not a single template repeated a thousand times.

Think about what your org actually sees. A Service Cloud org probably has a heavy mix of screenshots and small PDFs attached to Cases. A Financial Services Cloud org likely has larger signed documents and statements. Match the ratio, not just the count, and set PathOnClient with a real extension (.pdf, .png, .docx) rather than a generic .txt, since the FileType field and downstream rendering logic both key off that extension.

Generating that size variation manually means maintaining a library of sample binaries and remembering to base64-encode them correctly for every batch. SproutEzee reads the picklist and field metadata around your Files-enabled objects and generates sized, extension-correct placeholder content automatically, so the distribution mirrors production without someone hand-curating sample PDFs.

ContentDocumentLink Edge Cases That Trip Up Bulk Loads

LinkedEntityId is not limited to standard objects. Custom objects work fine as long as the "Allow attachments" or Files-related setting is enabled, but if you try to link a file to an object that does not support it, the row fails silently in a batch job rather than throwing a loud, obvious error. Always test the link path on a handful of records before scaling to thousands.

Visibility has three values: AllUsers, InternalUsers, and SharedUsers. Test data meant to validate Experience Cloud community file sharing needs AllUsers or SharedUsers specifically, because InternalUsers hides the file from portal and community users entirely. If your community-facing test cases keep failing to render an attached file, check this field before you check anything else in the page layout.

ShareType controls whether the linked user can edit (V for Viewer with inferred permission, C for Collaborator, I for Inferred from the parent record). Most test scenarios want I, letting the file inherit sharing from its parent record, but if you are specifically testing collaborative editing permissions, you need to set this explicitly rather than rely on the default.

Batching Strategy for High-Volume File Test Data

Base64 inflation changes your batching math. A normal Bulk API v2 job comfortably handles tens of thousands of standard object rows per batch. With ContentVersion, the practical row count per batch drops sharply once average file size climbs past a few hundred KB, simply because the encoded payload eats into the 150MB per-batch ceiling faster than anyone expects on a first attempt.

The fix is chunking by total payload size rather than row count. Instead of asking "how many records per batch," ask "how many megabytes of encoded content per batch," and size your batches to stay comfortably under the limit with room for job metadata overhead. This is a different mental model from loading Accounts, and teams that skip this step are the ones who see jobs fail two-thirds of the way through a large file-generation run.

SproutEzee calculates this automatically from the org schema and the target file-size distribution, splitting jobs by encoded payload weight instead of a fixed row count, which keeps large-file batches from stalling out mid-run. It is a small detail, but it is the difference between a file test data job that completes in one pass and one that needs three retries and a support ticket.

Opinion: Stop Treating Files as an Afterthought in Test Data Plans

Most test data strategies I have reviewed treat Files and Attachments as a checkbox item, something to populate once with a handful of sample PDFs and never revisit. That is a mistake for any org where file upload, preview, or sharing logic sits anywhere near a business process. Case escalation flows that attach screenshots, Opportunity approval processes that require signed quotes, Experience Cloud portals where customers upload documents — all of these depend on ContentVersion and ContentDocumentLink behaving correctly under realistic volume and variety.

Skipping proper file test data because the object model is annoying to work with is a short-term convenience that shows up as a production incident later. Build the size distribution, get the linking right, and budget the extra batching logic up front. It costs less than the alternative.

Frequently Asked Questions

Can Bulk API v2 insert ContentVersion records with actual file content?

Yes. The file content goes into the VersionData field as a base64-encoded string embedded directly in the CSV or JSON row, since Bulk API v2 has no separate binary channel. This inflates the payload size by roughly 33% compared to the raw file, which needs to be accounted for when sizing batches.

What does FirstPublishLocationId do when inserting ContentVersion?

Setting FirstPublishLocationId to a record ID on the ContentVersion insert causes Salesforce to automatically create the corresponding ContentDocumentLink, connecting the file to that record without a second insert. It only creates one link with default sharing settings, so scenarios needing multiple links or custom Visibility still require a separate ContentDocumentLink job.

Do I still need to insert ContentDocumentLink if I use FirstPublishLocationId?

Not for a single-parent, default-sharing scenario, since FirstPublishLocationId handles that link automatically. You do need a separate ContentDocumentLink insert if the test case requires sharing one file across multiple parent records or setting a non-default ShareType or Visibility value.

How large can test files be before Bulk API jobs start failing?

There is no hard per-file limit beyond Salesforce's general file size caps, but the practical constraint is the per-batch payload ceiling in Bulk API v2, typically around 150MB of encoded data per batch. Because base64 encoding adds about a third to the file's size, large files reduce how many rows safely fit in a single batch, so batching by total encoded size rather than row count avoids mid-job failures.

Can test data tools generate realistic file types like PDFs and images instead of plain text?

Yes, a well-built generator sets PathOnClient with the correct extension (.pdf, .png, .docx) so Salesforce's FileType field and downstream rendering logic treat the record correctly. SproutEzee additionally varies file sizes to match a realistic distribution for the target object rather than loading identical placeholder content for every record.