From 44c79241c9125d235b46643e363ba7cc2bc857d4 Mon Sep 17 00:00:00 2001 From: James Simone Date: Mon, 7 Jun 2021 13:09:20 -0600 Subject: [PATCH] Prettier formatting, extra safety --- .../log-management/classes/LogBatchPurger.cls | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/nebula-logger/main/log-management/classes/LogBatchPurger.cls b/nebula-logger/main/log-management/classes/LogBatchPurger.cls index 310a128b2..5e2de0686 100644 --- a/nebula-logger/main/log-management/classes/LogBatchPurger.cls +++ b/nebula-logger/main/log-management/classes/LogBatchPurger.cls @@ -47,7 +47,6 @@ global with sharing class LogBatchPurger implements Database.Batchable, this.hardDelete(safeToDeleteRecords); } - if (!this.recordsToDelete.isEmpty() && Limits.getLimitQueueableJobs() > Limits.getQueueableJobs()) { System.enqueueJob(this); } @@ -58,9 +57,14 @@ global with sharing class LogBatchPurger implements Database.Batchable, } private void hardDelete(List records) { - DELETED_COUNT += records.size(); - delete records; - Database.emptyRecycleBin(records); + // normally this would be an anti-pattern since most DML operations + // are a no-op with an empty list - but emptyRecycleBin throws + // for empty lists! + if (!records.isEmpty()) { + DELETED_COUNT += records.size(); + delete records; + Database.emptyRecycleBin(records); + } } } @@ -88,15 +92,13 @@ global with sharing class LogBatchPurger implements Database.Batchable, throw new LogBatchPurgerException('User does not have access to delete logs'); } - try { + // Delete the child log entries first + List logEntriesToDelete = [SELECT Id FROM LogEntry__c WHERE Log__c IN :logsToDelete]; if (this.isSystemDebuggingEnabled) { Logger.setParentLogTransactionId(this.originalTransactionId); - Logger.info(new LogMessage('Starting deletion of {0} records', logsToDelete.size())); + Logger.info(new LogMessage('Starting deletion of {0} logs and {1} log entries', logsToDelete.size(), logEntriesToDelete.size())); } - - // Delete the child log entries first - List logEntriesToDelete = [SELECT Id FROM LogEntry__c WHERE Log__c IN :logsToDelete]; new LogDeleter(logEntriesToDelete).process(); // Now delete the parent logs