Search code examples
c#salesforcehttpclient

C# HttpClient add header to allow duplicate record insert in Salesforce using salesforce Api


While using Salesforce Api to push data from C# to Salesforce objects, I got stuck for Contacts object not pushing data as it was already available in Contacts object. So there are two possibilities to cope with this.

  • Either use the existing Contact's object record id.
  • Or Allow duplicate record to be created in Contacts object.

On Salesforce you get a popup to create new or use existing one, but how you can know about duplication using Api.

After exploring more on Salesforce Api documentation, I found the following link to implement allow duplicates via Api. https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/headers_duplicaterules.htm

Now the question is how can I Include this header in HttpClient request?


Solution

  • The answer to this question, I tried

    client.DefaultRequestHeaders.Add("Sforce-Duplicate-Rule-Header", "allowSave=true;includeRecordDetails=false;");
    

    It did not work, but the following line worked.

    client.DefaultRequestHeaders.Add("Sforce-Duplicate-Rule-Header", "allowSave=true");
    

    It saved the duplicate Contacts Object record in Salesforce.