This error message contains a field name
and a record ID
, for example:
DUPLICATE_VALUE:duplicate value found: EngineeringReqNumber__c duplicates value on record with id: 5006g00000DklQA
โ
Note that record ID 5006g00000DklQA
is used only as an example here. It could be any record ID that fails.
What causes the error?
This error will only occur if the field (in this example, EngineeringReqNumber__c
) in the target org is unique.
What causes the error when the field is not unique in the source org?
We will see this error if the field is not unique
in the source org, and multiple source records in the deployment have the same value for the field.
If there is a record in the target with the same value for that field, no records will be deployed.
If there isn't a record in the target with this value for the field, one record will be deployed and the others will fail.
What causes the error when the field is unique in the source org?
If the field is unique in the source org, we'll see this error when we deploy a new record to the target org, which has the same value for the field as an existing record.
This can happen when:
- we choose to create new
records for the object
- we choose to upsert
records for the object, but there's no match on the external ID field for the source record, so a new record is created
If the target org is empty, we won't see this error.
How do I fix the error?
If the field is not unique in the source org, try to make it unique. This stops the source org from having multiple records with the same value for the field.
Salesforce won't let us make the field unique if there are already duplicate records. We should remove these duplicate values, using unique values for each record, and then make the field unique.
Once the field is unique in both the source and target orgs, we need to make sure that records can be matched during the deployment, to avoid creating new records with the same value for the unique field.
We can make the unique field into an external ID, and use the external ID for the upsert. The field needs to be an external ID in both the source and target org.
We can select the unique field as the one we want to use to match the records.
The deployment will match source and target records using the unique field, so it won't try to create any new records if a record already exists in the target with that value.