Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate detection issue by applying DML options with all-or-nothing behavior #1502

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading