Skip to content

Commit

Permalink
Merge pull request #1474 from SFDO-Community/feature/375-qualified-pa…
Browse files Browse the repository at this point in the history
…rent-id-duplicate-error

ignore DUPLICATE_VALUE on sched item errors
  • Loading branch information
aheber authored May 27, 2024
2 parents a099af2 + cc6d5c1 commit 5122ae3
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion dlrs/main/classes/RollupService.cls
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,32 @@ global with sharing class RollupService {
}
}
// These records drive the work done by the RollupJob Scheduled Apex Class
upsert scheduledItems QualifiedParentID__c;
List<Database.UpsertResult> results = Database.upsert(
scheduledItems,
LookupRollupSummaryScheduleItems__c.QualifiedParentID__c,
false /* allOrNone */,
AccessLevel.SYSTEM_MODE
);
// iterate through errors, only return an exception for something other than DUPLICATE_VALUE
// because DUPLICATE_VALUE errors are usually sharing problems and we're happy as long as the record is in the database
for (Integer i = 0, j = results.size(); i < j; i++) {
if (!results[i].isSuccess()) {
for (Database.Error err : results[i].getErrors()) {
if (err.getStatusCode() != System.StatusCode.DUPLICATE_VALUE) {
throw new DmlException(
'Upsert failed. First exception on row ' +
i +
'; first error: ' +
err.getStatusCode() +
', ' +
err.getMessage() +
': ' +
err.getFields()
);
}
}
}
}
}

// Process each context (parent child relationship) and its associated rollups
Expand Down

0 comments on commit 5122ae3

Please sign in to comment.