function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DSI Integration 6DSI Integration 6 

REST Sforce-Duplicate-Rule-Header Not Returning anything

I currently have a C# Web Application that is creating new Accounts in Salesforce using REST API. 

I would like to check for duplicates prior to creating the records using REST API. 

I recently discovered Sforce-Duplicate-Rule-Header (https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/headers_duplicaterules.htm). 

After adding the header to my HTTP Requests, I expected to receive a response with all fields in the duplicate record when the record being created is determined to be a duplicate based on my Duplicate Rules for Account Object.

Am I misinterpreting what this header is supposed to do for me?

HTTP Request (POST / Create for an Account that already exists):
Method: POST, RequestUri: 'https://XXXXX.my.salesforce.com/services/data/v52.0/sobjects/Account', Version: 1.1, Content: System.Net.Http.StringContent, Headers:
{
  Accept: application/json
  Authorization: Bearer XXXXX
  Sforce-Duplicate-Rule-Header: allowSave=false; includeRecordDetails=true; runAsCurrentUser=true
  Content-Type: application/json; charset=utf-8
},
Content:
{
  "Name":"Test Account",
  "First_Name__c":"Test",
  "Last_Name__c":"Account",
  "BillingStreet":"123 Main St",
  "BillingCity":"Pittsburgh",
  "BillingState":"PA",
  "BillingPostalCode":"12345",
  "Phone":"1234567890"
}
HTTP Response:
{
  "id":"XXXXX",
  "success":true,
  "errors":[]
}

Because the account already exists, I'd expect to get back all fields in the duplicate record.  At very least I'd expect something other than a successful creation. 

Am I misinterpretting what this header does or how to use it? 
Ashish Singh SFDCAshish Singh SFDC
Hi DSI,

It means the record that you're creating is not matching with the duplicate rule criteria. Revisit your Account Duplicate Rule once again in the environment where you're trying to create the record. Based on the rule try to create two records.

If => allowSave=false, then it will check if two or more records are satisying the duplicate rule and if yes then returns 400 error in response payload. It will return all the Account Id which are detected as the duplicate rule, Count of all Accounts, Name of the duplicate rule. See sample response for Contact from my Dev Org:
 
[
    {
        "duplicateResut": {
            "allowSave": true,
            "duplicateRule": "Salesforce_Contact_Duplicate_Rule",
            "duplicateRuleEntityType": "Contact",
            "errorMessage": "Use one of these records?",
            "matchResults": [
                {
                    "entityType": "Contact",
                    "errors": [],
                    "matchEngine": "FuzzyMatchEngine",
                    "matchRecords": [
                        {
                            "additionalInformation": [],
                            "fieldDiffs": [],
                            "matchConfidence": 73.0,
                            "record": {
                                "attributes": {
                                    "type": "Contact",
                                    "url": "/services/data/v52.0/sobjects/Contact/0033500000XXXX"
                                },
                                "Id": "00335000XXXXXX"
                            }
                        },
                        {
                            "additionalInformation": [],
                            "fieldDiffs": [],
                            "matchConfidence": 73.0,
                            "record": {
                                "attributes": {
                                    "type": "Contact",
                                    "url": "/services/data/v52.0/sobjects/Contact/00335000YYYYYY"
                                },
                                "Id": "00335000YYYYYY"
                            }
                        }
                    ],
                    "rule": "Salesforce_Contact_Duplicate_Rule",
                    "size": 2,
                    "success": true
                }
            ]
        },
        "errorCode": "DUPLICATES_DETECTED",
        "message": "Use one of these records?"
    }
]



If=>allowSave=true
Records will be created with 200 Code.

Thanks,
Ashish Singh.