Skip to content

Commit

Permalink
Merge pull request #1502 from SFDO-Community/feature/1007
Browse files Browse the repository at this point in the history
Fix duplicate detection issue by applying DML options with all-or-nothing behavior
  • Loading branch information
aheber authored Oct 8, 2024
2 parents 65c8e97 + 66910f7 commit 6db4cee
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion dlrs/main/classes/RollupService.cls
Original file line number Diff line number Diff line change
Expand Up @@ -1661,8 +1661,19 @@ global with sharing class RollupService {
masterRecords.set(outerIndex, masterRecords.get(indexOfMin));
masterRecords.set(indexOfMin, temp);
}
// Create DmlOptions instance
Database.DMLOptions dml = new Database.DMLOptions();

// Allow save even if duplicates are detected
dml.DuplicateRuleHeader.allowSave = true;

// Run as current user to enforce sharing rules
dml.DuplicateRuleHeader.runAsCurrentUser = true;

dml.OptAllOrNone = allOrNothing;

try {
return Database.update(masterRecords, allOrNothing);
return Database.update(masterRecords, dml);
} catch (DMLException e) {
// Determine if the exception is due to parent record/s having been deleted
Boolean throwException = true;
Expand All @@ -1685,6 +1696,7 @@ global with sharing class RollupService {
return new List<Database.Saveresult>();
}
// Throw on as normal

throw e;
}
}
Expand Down

0 comments on commit 6db4cee

Please sign in to comment.