Repository navigation
Fix #1026: handle DELETE_OPERATION_TOO_LARGE in LogBatchPurger - #1030
Draft
RajPabnani03 wants to merge 1 commit into
Draft
RajPabnani03 wants to merge 1 commit into
RajPabnani03 wants to merge 1 commit into
Conversation
A batch delete can fail when the DML cascades to too many related records at once (e.g., DELETE_OPERATION_TOO_LARGE on LogEntry__c or FeedItem records), which caused the whole LogBatchPurger job to fail with an unhandled exception and prevented deletable records from being purged. On a DmlException from the all-or-none delete, LogBatchPurger now retries with a partial delete: successfully deleted records are still purged (and removed from the recycle bin), and any records that still fail are logged as errors when system messages are enabled. The job then continues instead of failing the batch. Also adds a virtual emptyRecycleBin() method to LoggerDataStore.Database so the full delete chain remains mockable in tests.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1026 —
LogBatchPurger.execute()performed a single all-or-nonedeleteon the batch scope, so when the DML cascaded to too many related records at once (DELETE_OPERATION_TOO_LARGEonLogEntry__corFeedItemrecords), the entire batch failed with an unhandled exception and none of the scope was purged.LogBatchPurgernow wraps the delete inhardDeleteRecords(scopeRecords)and, on aSystem.DmlException, retries viahardDeleteRecordsWithPartialDeletes(scopeRecords):Logger.errorentries (gated onEnableLoggerSystemMessages, matching the class's existing convention) instead of "Failed to process batch" unhandled-exception emails; they're re-attempted on the next scheduled run.emptyRecycleBin(List<SObject>)method toLoggerDataStore.Database(and routeshardDeleteRecordsthrough it) so the whole delete chain stays mockable;hardDeleteRecord/hardDeleteRecordssignatures are unchanged.Adds
it_should_partially_delete_records_when_batch_delete_throws_dml_exceptiontoLogBatchPurger_Tests, using a newMockPartiallyFailingDatabasethat throws on the all-or-none delete and returns mixed results on the partial delete.Testing
Verified in a scratch org (Enterprise Edition, API v67): full
nebula-logger/coredeploy succeeded and the complete local Apex suite passed — 1260/1260 tests, 93% org-wide coverage — including the newit_should_partially_delete_records_when_batch_delete_throws_dml_exception(mockedLoggerDataStore.Databasecovering the fallback path).