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
forceguy.ax1264forceguy.ax1264 

Upsert failure on duplicate value

we published a service in SF which other clients call. the service receives some data..applies some business logic/process and upserts based on a custom field which is set as external Id(unique). if  the external id value doesn't exist in sf  and we receive the same data back to back(within minute gap like millisecods) or two calls made to our service at the same time the second call is failing and give and error "Insert failed. First exception on row 0; first error: DUPLICATE_VALUE".

My guess here is while the first call is committing data to DB the second call upsert code is trying to look if the ext id value already exists and is not able to find the ext id match and it is trying to insert and then failing.

has any body experienced this or have a solution, please share.

 

Thanks in advance.