How to fix DUPLICATE_EXTERNAL_ID in Salesforce deployments
An upsert matches more than one existing record on the same external ID value, so Salesforce can't tell which one to update.
Surfaces during: upsert DML in data loads, integrations, and ApexWhat it means
DUPLICATE_EXTERNAL_ID means an upsert call found more than one record in the target org sharing the same value in the external ID field being matched on. Upsert relies on that field being genuinely unique per record; when duplicates exist, Salesforce has no way to decide which record the incoming data should update, so it rejects the operation instead of guessing.
This is purely a data-state problem in the target org, not something wrong with the incoming payload itself; the same upsert call would succeed the moment the target org's duplicate values are resolved.
Common causes
The fix
- Dedupe records sharing the external ID firstQuery the target org for the offending value, decide which record is authoritative, and merge or delete the rest before retrying.
SELECT External_Id__c, COUNT(Id) FROM Account GROUP BY External_Id__c HAVING COUNT(Id) > 1 - Turn on the Unique attribute on the fieldEdit the external ID field definition so Salesforce enforces uniqueness going forward and blocks new duplicates at insert time.
- Use a more specific composite keyIf two legitimately different records can share the base value, combine it with a second field so the match is unambiguous.
How Serpent prevents this
Serpent keeps every sandbox and scratch org synced from the same source, so duplicate external ID values from stale, hand-loaded data are far less likely to build up between environments. See the Salesforce deployment error library.

Prevention
Related errors
DUPLICATE_EXTERNAL_ID, answered
Start free. No credit card, no install, no commitment.
Set up in under 15 minutes. No DevOps hire needed.
