Salesforce.com Known Issues and Workarounds

Here are some Salesforce.com known issues learned while developing applications or customer projects. Hope you find these useful.

Feel free to add comment below if you would like to share known issues or workarounds you found and someone may benefit from it.

Duplicate Custom Setting (List type) record when concurrent requests are executed via APEX.

Ref: https://trailblazer.salesforce.com/issues_view?id=a1p300000008YiiAAE

When a user attempts to create a record/row on a List type Custom Setting, it can cause duplicate records if the request is executed via APEX.

Error message:

FATAL_ERROR System.DmlException: Upsert failed. First exception on row 15; first error: DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record with id: <unknown>: []

Workaround: Try to insert/upsert few records at a time, 5 records worked for us.

Code:

/* Upsert reocords in smaller batches as Custom setting records can not be inserted all at once

  causing duplicate value error.

*/

public static void upsertRecordBatches(List<sObject> records,Integer batchSize) {

    Integer counter = 0;

    List<sObject> batchForUpsert = new List<sObject>();

    for (sObject aRecord: records) {

         batchForUpsert.add(aRecord);

         counter += 1; //increment counter

         if (counter >= batchSize) {

              database.upsert(batchForUpsert);

              batchForUpsert.clear();

              counter = 0;

         }

    }

}

Usage:

        <classname>.upsertRecordBatches(dataMappings,5);

 

Salesforce.com Known Issues and Workarounds
Tagged on:         

Leave a Reply

Your email address will not be published.