I am using this API package to Upsert a Lead onto Salesforce using a custom External ID which is the user's email stored in MySQL. Once a while, due to no reason whatsoever, Salesforce would cry out about a Duplicate Record when that email e.g. [email protected] does't exist in Salesforce now or never. It simply doesn't exist anywhere.

Why would this happen?

GuzzleHttp\Exception\ClientException: Client error: `PATCH https://omitted-dev.my.salesforce.com/services/data/v42.0/sobjects/Lead/MySQL_Email__c/[email protected]` resulted in a `400 Bad Request` response:
[{"message":"You're creating a duplicate record. We recommend you use an existing record instead.","errorCode":"DUPLICAT (truncated...)

Salesforce crying about this when the Lead IDs have two different emails

enter image description here

Expanded error message:

[{"message":"You're creating a duplicate record. We recommend you use an existing record instead.","errorCode":"DUPLICATES_DETECTED","fields":[]}]

I just observed the logs on Apex debug console while making the request again from my failed queue, and I see this:

01:55:23:077 DUPLICATE_DETECTION_MATCH_INVOCATION_DETAILS EntityType:Lead|ActionTaken:Allow_[Alert,Report]|DuplicateRecordIds:00Q1r00001CojKl.


2 Answers 2


Based on the error message this is the result of a Duplicate Rules detecting something between the upserted Lead and an existing record.

You can check the exact details either via the Apex Debug logs for the transaction or using the Duplicate Error Logs.

From your message, it is showing the Duplicate rule is: Standard Rule for Leads with Duplicate Contacts

You can verify this by taking the ID that starts with the keyprefix 0Bm and putting it on the URL in the Org.

You will get something like this:

enter image description here

Which basically means you were inserting a Lead and the Duplicate rule found a matching Contact. It is using a special inbuilt Standard Contact and Lead Matching Rule

(First Name AND Last Name AND Title AND Account Name) OR (First Name AND Last Name AND Email)

OR (First Name AND Last Name AND Phone AND Account Name)

OR (First Name AND Last Name AND Mailing Street AND (City OR ZIP OR Phone)

OR (First Name AND Last Name AND Mailing Street AND Title)

OR (First Name AND Last Name AND Title AND Email)

OR (First Name AND Last Name AND Phone)

From the comment thread:

So to clarify for whoever is reading this answer. The duplicate check of FN AND LN AND PHONE was being triggered hence preventing the lead creation. This doesn't happen ever in the real world so a non-issue.
– Ali Gajani

Note that the SOAP API provides the ability to bypass the Duplicate Rules using the DuplicateRuleHeader. As far as I'm aware there is no direct equavalent for the REST API at this time. See the idea : Enable Duplicate Management control through REST API.

Worst case you could resort to manually making your own version of the REST API that allows you to specify the DuplicateRuleHeader on the DML in Apex.


we are facing similar issue of lead sync from heroku connect.

So even if we disable standard duplicate rules will there be an chance that it runs?

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .