The DUPLICATE_VALUE  and DUPLICATE_EXTERNAL_ID  errors can happen during a data deployment if you're upserting records.

What causes the error?

When upserting, Gearset tells Salesforce to use an external id field to match records between the source and target. If multiple records have the same value for the external id field, Salesforce will throw an error during the upsert.

The DUPLICATE_VALUE  error means that one or more records being deployed from the source have the same value for the external id field. Salesforce doesn't know which record to use for the upsert so throws an error.

The DUPLICATE_EXTERNAL_ID  error means that one or more records in the target have the same value for the external id field. Salesforce doesn't know which record to upsert so throws an error.

How do I fix the error?

There's a few ways to avoid this error.

Use a different external id for upserting

Ideally you would have an external id which doesn't allow duplicates.

Using this external id field for the upsert means that there won't be duplicates, so we won't hit these errors.

You might also have a Duplicate Rule against an external id field to the same effect.

Create new records instead of upserting

Creating new records instead of upserting existing records will avoid these errors.

If you have a Duplicate Rule in the target, you may run into a different errors. Deactivating the Duplicate Rule during the deployment will help avoid this.

Exclude the records causing errors from the deployment

It may be a few records causing the errors. You can use Gearset's data deployment filters to exclude these records from your deployment.

Once you've successfully deployed the rest of the data, you can try using a different external id to upsert the remaining records.

Did this answer your question?