Guides / n8n × Salesforce / Data Sync

Fix Salesforce “DUPLICATE_VALUE” When Creating Records From n8n

Why a Salesforce Create operation from n8n fails with DUPLICATE_VALUE or DUPLICATES_DETECTED, and the search-before-create pattern that fixes it for good.

Illustrated flow showing an n8n workflow searching Salesforce for an existing record before creating a new one to avoid duplicates.
DUPLICATE_VALUE: duplicate value found: <Field> duplicates value on record with id: 00Q... — or — DUPLICATES_DETECTED: Use one of these records?
Short answer: DUPLICATE_VALUE means a field marked Unique (often an External ID, email, or a custom unique key) already has a matching value on an existing record — the create is being rejected at the database layer. DUPLICATES_DETECTED is a different, softer mechanism: Salesforce's built-in Duplicate Rules matched the new record against existing ones using fuzzy matching (name, phone, address) and are blocking or warning on the create by rule configuration, not because of a hard-unique field. Both need the same underlying fix in n8n: search for a likely-existing record before creating, and branch to update instead of insert when a match is found.

Two different Salesforce mechanisms, two different fixes

DUPLICATE_VALUE comes from a database-level unique constraint on a specific field — most often an External ID field, a formula field marked Unique, or a standard field like Email on Contact/Lead when your org has "Require Unique Case-Insensitive Email" or similar validation enabled. This is deterministic: the exact field and the exact colliding record ID are named in the error.

DUPLICATES_DETECTED comes from Salesforce's Duplicate Rules and Matching Rules feature (Setup → Duplicate Rules), which runs fuzzy matching — similar company name, similar phone number, similar address — and can be configured per-object to either Block or Allow with a warning. If your org's Duplicate Rule for Leads or Accounts is set to Block, an n8n Create operation that would have otherwise succeeded gets rejected with DUPLICATES_DETECTED and a list of the records it thinks are duplicates, even if none of your individual fields violate a hard uniqueness constraint.

Check which error you're actually getting before choosing a fix. DUPLICATE_VALUE names the exact colliding field and record ID; DUPLICATES_DETECTED names a Duplicate Rule and a set of possible matches. The remediation pattern below (search before create) fixes both, but the search you build should target the same field the specific error is complaining about.

The fix: search before create, then branch

The reliable pattern — the same one used across most CRM integrations, including the equivalent HubSpot "search open deal before create" pattern many n8n workflows already use — is to search Salesforce for a record matching your natural key (email, external ID, or the same fields your Duplicate Rule matches on) immediately before the Create step, then use an IF node to route to Update when a match exists and Create only when it doesn't.

  • Salesforce node → Search: query the object using the same field the DUPLICATE_VALUE error named, or the fields your Duplicate Rule matches on (name + phone, or email).
  • IF node: check whether the Search step returned any records.
  • True branch (match found): Salesforce node → Update, using the existing record's Id.
  • False branch (no match): Salesforce node → Create, as originally designed.
-- SOQL used by the Search step (adjust fields to match your object and the specific unique/duplicate-rule fields involved)
SELECT Id, Name, Email
FROM Contact
WHERE Email = '{{ $json.email }}'
LIMIT 1

If it's DUPLICATES_DETECTED: consider Allow-with-warning instead of Block

For DUPLICATES_DETECTED specifically, there's a second option beyond search-before-create: ask whoever administers the Salesforce org to review the relevant Duplicate Rule (Setup → Duplicate Rules) and change its action from Block to Allow (optionally with the Alert checkbox left on, so a human still sees a warning banner in the UI) for API-created records, if your business process is fine with occasional near-duplicates that a human can merge later. This is a policy decision for the Salesforce admin, not something to change from n8n, but it's worth raising if the search-before-create pattern above still produces false-positive matches on fuzzy Duplicate Rules (e.g. two genuinely different companies with similar names).

Batch workflows: search per item, not once for the whole batch

If your n8n workflow processes many items in one execution (e.g. a scheduled sync pulling 200 rows from a spreadsheet), make sure the Search step runs once per item — inside a Split In Batches loop or with the Salesforce node's own per-item execution — rather than a single search that only checks the first item. A single upfront search that passes for item 1 but silently lets items 2–200 hit the same DUPLICATE_VALUE error is a common way this pattern gets implemented incorrectly.

When the match key itself resolves to more than one record

Upsert matches on an External ID field. If two existing records already share the value you send, Salesforce cannot decide which one to update and returns a 300 Multiple Choices response with a list of matching record URLs, rather than DUPLICATE_VALUE. The built-in node usually reports this as a failure without the detail.

The fix is on the Salesforce side: find and merge or correct the pre-existing duplicates so the External ID is genuinely unique, then re-run. Marking the field "Unique" in its definition prevents new duplicates but does not clean up ones that predate the flag.

Case sensitivity is a related surprise. A Unique text field is case-insensitive by default, so "ACME-01" and "acme-01" collide; if the field was set to case-sensitive, they do not. Know which mode your key field uses before assuming a value is safe.

  • Two existing records sharing the External ID value produce an HTTP 300 Multiple Choices, not DUPLICATE_VALUE.
  • Resolve by merging or correcting the existing duplicates in Salesforce first.
  • Unique text fields are case-insensitive unless explicitly set otherwise.

Prevent it, do not just catch it

You can set the Salesforce node to Continue On Fail and branch on the returned errorCode, routing DUPLICATE_VALUE to an Update using the record ID named in the error message. That works, but it means every collision costs a failed API call, fills the execution log with errors that are not really errors, and depends on parsing an ID out of an error string.

Search-before-create avoids all of that: one deterministic query, a clean IF branch, and no failed writes. Reserve the catch-and-branch approach for cases where you genuinely cannot predict the match key ahead of time - for example, DUPLICATES_DETECTED from fuzzy Duplicate Rules that match on a combination of fields you are not indexing yourself.

  • Catch-and-branch: works, but every duplicate is a failed API call and a noisy log line.
  • Search-before-create: one clean query, no failed writes, deterministic.
  • Use catch-and-branch only when the match key is genuinely unpredictable.

DUPLICATES_DETECTED tells you which records it matched

The error body for a duplicate-rule rejection is far more useful than the message string suggests. Alongside the errorCode, Salesforce returns a duplicateResult object naming the rule that fired, the matching rule it used, and the specific records it considers duplicates — complete with their IDs and the field values that matched. A workflow with Continue On Fail enabled can read that structure directly instead of guessing what the fuzzy match objected to.

That opens a third option beyond search-before-create and asking an admin to relax the rule. Where the matched record is genuinely the same entity, branch to an update against the ID Salesforce already handed you — no extra query needed, because the lookup has effectively been done for you. Where it is a false positive, the same structure gives you the evidence to take to whoever owns the rule.

There is also a documented override. Adding the Sforce-Duplicate-Rule-Header with allowSave=true to a REST call tells Salesforce to save the record despite a duplicate rule set to Block. Use it deliberately and narrowly — for a migration, or for a source system you trust more than the fuzzy match — and never as a blanket header on every write, because it disables a control the business chose to switch on.

# What a duplicate-rule rejection actually contains
HTTP 400
[{ "message": "You're creating a duplicate record. We recommend you use an existing record instead.",
   "errorCode": "DUPLICATES_DETECTED",
   "duplicateResult": {
     "duplicateRule": "Standard_Contact_Duplicate_Rule",
     "matchResults": [{
       "matchEngine": "FuzzyMatchEngine",
       "entityType": "Contact",
       "matchRecords": [{ "record": { "Id": "003XX000004TmiQ", "Name": "Ada Lovelace" } }]
     }]
   }}]

# -> branch to an Update against 003XX000004TmiQ, no extra query required.

# Deliberate override, for a migration or a trusted source only:
POST /services/data/v62.0/sobjects/Contact
Sforce-Duplicate-Rule-Header: allowSave=true
Content-Type: application/json

{ "LastName": "Lovelace", "Email": "ada@example.com" }

Sources and further reading

DUPLICATE_VALUE and DUPLICATES_DETECTED are both standard, documented Salesforce API error codes tied respectively to unique field constraints and the platform's Duplicate Rules/Matching Rules feature. The search-before-create branching pattern mirrors the equivalent duplicate-prevention pattern already documented for n8n's HubSpot integration on this site, applied to Salesforce's Search + IF + Update/Create nodes.

Frequently asked questions

What's the difference between DUPLICATE_VALUE and DUPLICATES_DETECTED?

DUPLICATE_VALUE is a hard database constraint violation on a field explicitly marked Unique (or an External ID) — the exact field and colliding record ID are named. DUPLICATES_DETECTED comes from Salesforce's separate Duplicate Rules feature, which does fuzzy matching on things like name, phone, and address, and can be configured to Block or just warn.

Can I just catch the error and ignore it instead of searching first?

You can set the Salesforce node to "Continue on Fail" and catch the error downstream, but that only tells you a duplicate exists after the failed create — it doesn't give you the existing record's Id to update, so you'd still need a follow-up search. Searching before create gets you the Id in the same pass and avoids the failed API call entirely.

My Duplicate Rule's action is set to Allow (with the Alert checkbox on) — will n8n's Create still fail?

No. When the rule's action is Allow, Salesforce lets the create succeed and just surfaces a warning banner in the UI (or logs the alert internally for API calls); it does not return a DUPLICATES_DETECTED error to the API caller. That error only appears when the rule's action is set to Block.

Can I find out which record Salesforce thinks is the duplicate?

Yes. The DUPLICATES_DETECTED error body carries a duplicateResult object with matchResults listing the matched record IDs. Enable Continue On Fail and read it — you can branch straight to an update without running a second query.