0

I send next upsert request to Salesforce:

PATCH /services/data/v41.0/sobjects/Task/uuid__c/a22ac4d6-e2c0-4e53-898d-ea1d0c807775 HTTP/1.1
Host: **********.my.salesforce.com
Content-Type: application/json; charset=UTF-8
Accept: application/json
Authorization: Bearer *******

{
  "Description": "Called C to discuss the reinstall.",
  "CallType": "Outbound",
  "OwnerId": "************",
  "Status": "Completed",
  "Subject": "Call",
  "isTransfer__c": false,
  "WhatId": "************",
  "CallDurationInSeconds": 597,
  "AudioFile__c": "outgoing/2017-10-31/03-10-59_ID-***********.mp3",
  "CallStarted__c": "2017-10-31T07:10:51Z",
  "CallHangup__c": "2017-10-31T07:20:56Z",
  "AsteriskId__c": "7794786",
  "ReasonText__c": "Success call"
}

uuid__c field is Unique, Case Insensitive and external id marked.

I receive next response from Salesforce:

[
    {
        "message": "duplicate value found: uuid__c duplicates value on record with id: *******************",
        "errorCode": "DUPLICATE_VALUE",
        "fields": []
    }
]

How it can be if UPSERT request must update object when duplicate found?

I have used this documentation for developing: Insert or Update (Upsert) a Record Using an External ID

2
  • Quick question, does the uuid__c of the record mentioned on the error match the uuid__c of your request? Oct 31, 2017 at 11:10
  • Yes, object has same uuid__c value. (So first upsert completed successfully, it cannot just made update of it) Oct 31, 2017 at 11:52

2 Answers 2

6

After a month of discussions with Indian support of all tiers, we've got next:

Salesforce can't proceed too fast UPSERT queries. If you send two requests with delay about a second or less you'll get next:

  1. Your request 1 come to Salesforce and start to save into their DB.
  2. Your request 2 come while first request still in work.
  3. Salesforce return DUPLICATE_VALUE on second request because it think there is no such data in DB yet, and will try to save it also via UPSERT.
  4. You've got error above.

OFFICIAL SOLUTION: Send your requests with delay at least 2 second each. At least first save completed.

Also from my request, they created an article with description: Salesforce Article

P.S. They will not change anything, about this behaviour. We spent a month, trying to resolve this issue and find the reason with PREMIUM Salesforce support, but results you can see in this answer.

-1

The documentation you are referring to says:

Error responses If the external ID value isn't unique, an HTTP status code 300 is returned, plus a list of the records that matched the query.

Which means: if you have created (somehow when uuid__c wasn't unique) two records with the same value of uuid__c, then you made uuid__c field unique and you are trying to update one of the two records with the same value of uuid__c then this will always cause an error.

To resolve this conflict you need change value of uuid__c on one record to some unique value.

3
  • Hi and thank you for answer, but it is wrong. 1) I receive code 400 2) uuid__c has already unique index in Salesforce. Also it can't be made unique if there are any duplicates values, so I removed all duplicates and made it unique index before start to use it as ExternalID. (To make it ExternalID there must be no duplicates) So uuid__c currently - unique + externalid Oct 31, 2017 at 20:55
  • @KorbenDallas, your request 1 and request 2 that come to salesforce within less than 1 second , Do they have same value in uuid__c or different values ?
    – apn
    Oct 26, 2018 at 0:26
  • @apn I have same uuid__c as I'm creating and then updating a call entity. Oct 26, 2018 at 6:31

You must log in to answer this question.

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