Salesforce external ID test data needs a different design approach than a standard insert dataset because upsert operations resolve records by key value, not by Salesforce record ID. Get the key values wrong and Bulk API v2 either creates duplicates it should have matched, or throws DUPLICATE_EXTERNAL_ID errors on values that should have been unique. The failure mode is quiet too — a sloppy external ID dataset often loads successfully and then silently corrupts downstream matching logic in your integration.

Most teams test external ID fields the way they test any other field: generate a value, load it, confirm the record exists. That approach misses the entire point of an external ID, which is to simulate how a second system identifies the same record over multiple syncs. Testing upsert behavior properly means testing what happens on the second, third, and fourth load, not just the first.

Why external ID test data breaks differently than other loads

A standard insert test dataset only has to satisfy field types, required fields, and validation rules. External ID fields carry an extra constraint: uniqueness across the object, enforced at the database level when the field is marked as an external ID. That constraint does not care whether your test data looks realistic. It cares whether two rows share a value.

Generators that produce external IDs with low entropy — sequential integers starting at 1, or a UUID library seeded the same way every run — will eventually collide across test cycles if old test data isn't purged first. A collision during an insert-only load just fails the record. During an upsert, it does something worse: it matches your new test record against stale data from a previous run and overwrites it, and the test passes even though the behavior under test never actually ran.

This is the opinion part, and I'll state it plainly: if your external ID test data generator doesn't account for what's already sitting in the sandbox, it isn't an external ID generator, it's a random string generator with extra steps. Uniqueness has to be checked against existing org data, not just within the batch being generated.

How Bulk API v2 upsert actually resolves external IDs

When a Bulk API v2 job runs as an upsert operation, Salesforce looks up each incoming row by the specified external ID field before deciding whether to insert or update. Three outcomes are possible for each row: no match (insert a new record), exactly one match (update that record), or more than one match (reject the row with a duplicate external ID error, assuming the field isn't marked as unique and multiple non-unique matches exist).

That third outcome is the one most test plans never exercise. Admins build datasets where every external ID is distinct by construction, run the upsert, see green checkmarks, and call it done. But production data rarely stays that clean. A legacy migration, a merge of two source systems, or a field that used to allow duplicates before someone added the unique constraint — any of these can leave an org with multiple records sharing an external ID value that predates the constraint.

Test data has to recreate that mess on purpose. Load a batch with intentional duplicate external ID values against a non-unique external ID field, confirm the upsert fails the way you expect, and check that your integration's error handling actually catches and logs the rejection instead of swallowing it.

Generating external ID values that mirror your source system

Real external IDs are not random. They come from somewhere — a legacy CRM's primary key, an ERP's customer number, a middleware-generated correlation ID. Each of those sources has a shape: fixed length, a prefix, a checksum digit, a date-encoded segment. Test data that ignores this shape can pass every validation rule and still fail to catch bugs tied to parsing logic that expects a specific format.

Consider a common case: an external ID field sourced from a legacy system that used zero-padded 10-digit numeric strings, like 0004471920. If your test data generator produces plain integers without padding, any formula field or trigger logic that parses substring positions out of that external ID will behave differently in test than it will against real data. The bug surfaces in production, not in your sandbox, which defeats the purpose of testing at all.

SproutEzee reads the field metadata — length, format mask if one exists, and any pattern inferred from sampled production values — and generates external ID values that match that shape while staying schema-compliant and free of real customer data. That's the balance: realistic enough to catch format bugs, synthetic enough to pass a security review.

Testing duplicate and null external ID scenarios on purpose

A thorough external ID test plan treats edge cases as first-class citizens, not afterthoughts. The table below outlines the scenarios worth building into every upsert test dataset, along with the behavior each one should confirm.

ScenarioWhat it testsExpected result
Unique new external IDStandard insert pathRecord created, no match found
Matching existing external IDStandard update pathExisting record updated, no new record created
Duplicate external ID in same batchBatch-level collision handlingBulk API v2 rejects or flags the conflicting rows
Null external ID valueFallback insert behaviorRecord inserted as new, since null never matches
Case-sensitivity mismatchText-based external ID comparison rulesMatch or mismatch depending on field case sensitivity setting

The null scenario trips up more teams than it should. A null external ID value doesn't raise an error on upsert. It just falls through to an insert every time, because Salesforce can't match on an absent value. If your source system occasionally sends records without a populated key — which happens more often than any integration spec admits — your test data needs rows with that field deliberately left blank so you can confirm the resulting duplicate records get flagged somewhere downstream instead of piling up silently.

Cross-object relationships and composite external IDs

External ID fields aren't just used to upsert a single object. Salesforce also lets you reference a parent record by its external ID in a lookup or master-detail relationship during a data load, which is one of the more useful tricks in a migration or integration scenario — and one of the easier things to get wrong in test data.

Say your Contact object looks up to Account, and the integration populates that lookup using the Account's external ID rather than its Salesforce record ID. Your Contact test data then depends on the Account test data existing and being loaded first, with matching external ID values on both sides. Generate the Contact batch independently and you'll get a pile of unresolved relationship errors that have nothing to do with the Contact fields themselves and everything to do with load sequencing.

Composite external IDs make this harder still. Some orgs build a external ID field as a formula-like concatenation — source system code plus record number, for instance, like SYS01-4471920 — to guarantee uniqueness across multiple feeding systems. Test data covering this pattern needs to vary both components independently: same record number from two different source system codes should not collide, but the same full composite value should always match the same record. Generating these values correctly requires understanding the relationship definitions in the schema, not just the field's data type, which is why schema-aware generation matters more here than almost anywhere else in test data design.

Building a repeatable external ID test dataset with SproutEzee

None of this works as a one-time exercise. Integrations change, source systems get swapped, and external ID formats shift when a company migrates off a legacy platform. Test data generation for external ID fields has to be repeatable across sandbox refreshes, not something an admin rebuilds by hand every quarter.

SproutEzee reads org schema directly, including which fields carry the external ID flag, whether the unique constraint is enabled, and what relationships depend on that field for lookups. It generates values through Bulk API v2 that respect format patterns, deliberately seeds the duplicate and null edge cases on request, and sequences cross-object loads so parent external IDs exist before dependent records try to reference them.

The result is a dataset an admin can regenerate after every sandbox refresh without manually re-deriving format rules or chasing load-order errors. Upsert testing stops being a one-off validation step and becomes something that runs the same way, with the same coverage, every single time the schema or the integration changes.

Frequently Asked Questions

What happens if an external ID field has no unique constraint during an upsert?

Without the unique constraint enabled, Salesforce allows multiple records to share the same external ID value. An upsert against that field will fail with a duplicate external ID error whenever more than one matching record is found, because the system cannot determine which record to update. Test data should include this exact scenario to confirm your integration handles the rejection instead of retrying blindly.

Can Bulk API v2 upsert records using a null external ID value?

Yes, but the result is always an insert rather than an update, since Salesforce cannot match a blank value against existing records. This behavior is easy to miss in testing because it never produces an error, it just quietly creates duplicate records over time. Test datasets should deliberately include null external ID rows to confirm downstream deduplication logic catches the resulting extras.

How should test data handle composite external ID fields?

Composite external IDs, such as a source system code concatenated with a record number, need test values that vary each component independently rather than treating the whole string as one random token. This confirms that uniqueness is enforced on the full combined value and not accidentally on just one segment. Schema-aware generation tools can build these values directly from the field's format pattern instead of requiring manual construction.

Why does case sensitivity matter for external ID test data?

Text-based external ID fields can be configured as case-sensitive or case-insensitive, and that setting changes what counts as a match during upsert. A value like ABC123 and abc123 will match on a case-insensitive field but be treated as two distinct records on a case-sensitive one. Test data should include mixed-case variants of the same base value to confirm the field behaves as configured rather than assumed.

How does external ID test data affect cross-object lookups during a load?

When a lookup or master-detail relationship is populated by external ID rather than Salesforce record ID, the parent records must exist with matching external ID values before the child records are loaded. Generating child and parent test data independently, without sequencing the load, produces unresolved relationship errors unrelated to the actual fields being tested. Tools that read the schema's relationship definitions can sequence these loads automatically so parent records land first.