From 41e6594c3c33683d9397558a2fd51a726970da79 Mon Sep 17 00:00:00 2001 From: patrick-skamarak <85705988+patrick-skamarak@users.noreply.github.com> Date: Tue, 19 Sep 2023 10:35:54 -0400 Subject: [PATCH] Bugfix for unhandled exception when email limits are reached (#548) * Added catch for System.HandledException in LoggerEmailSender.cls to avoid trying to send emails when the org's single email limit has been exceeded --- README.md | 10 +++++----- .../main/log-management/classes/LoggerEmailSender.cls | 5 ++++- .../core/main/logger-engine/classes/Logger.cls | 2 +- .../core/main/logger-engine/lwc/logger/logger.js | 2 +- .../classes/LoggerEmailSender_Tests.cls | 11 +++++++++++ package.json | 2 +- sfdx-project.json | 7 ++++--- 7 files changed, 27 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 5262f2185..b53d774c5 100644 --- a/README.md +++ b/README.md @@ -5,15 +5,15 @@ The most robust logger for Salesforce. Works with Apex, Lightning Components, Flow, Process Builder & Integrations. Designed for Salesforce admins, developers & architects. -## Unlocked Package - v4.11.2 +## Unlocked Package - v4.11.3 -[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y000001TsZAQA0) -[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y000001TsZAQA0) +[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y000001HZd0QAG) +[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y000001HZd0QAG) [![View Documentation](./images/btn-view-documentation.png)](https://jongpie.github.io/NebulaLogger/) -`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y000001TsZAQA0` +`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y000001HZd0QAG` -`sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y000001TsZAQA0` +`sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y000001HZd0QAG` --- diff --git a/nebula-logger/core/main/log-management/classes/LoggerEmailSender.cls b/nebula-logger/core/main/log-management/classes/LoggerEmailSender.cls index 4eaac7569..792c8dce3 100644 --- a/nebula-logger/core/main/log-management/classes/LoggerEmailSender.cls +++ b/nebula-logger/core/main/log-management/classes/LoggerEmailSender.cls @@ -31,9 +31,12 @@ public without sharing class LoggerEmailSender { if (IS_EMAIL_DELIVERABILITY_ENABLED == null) { try { System.Messaging.reserveSingleEmailCapacity(1); - System.Messaging.reserveMassEmailCapacity(1); IS_EMAIL_DELIVERABILITY_ENABLED = true; } catch (System.NoAccessException e) { + // Exception thrown when email deliverability is disabled + IS_EMAIL_DELIVERABILITY_ENABLED = false; + } catch (System.HandledException handledException) { + // Exception thrown when org limits are reached IS_EMAIL_DELIVERABILITY_ENABLED = false; } } diff --git a/nebula-logger/core/main/logger-engine/classes/Logger.cls b/nebula-logger/core/main/logger-engine/classes/Logger.cls index b25c108e4..888ec89a7 100644 --- a/nebula-logger/core/main/logger-engine/classes/Logger.cls +++ b/nebula-logger/core/main/logger-engine/classes/Logger.cls @@ -15,7 +15,7 @@ global with sharing class Logger { // There's no reliable way to get the version number dynamically in Apex @TestVisible - private static final String CURRENT_VERSION_NUMBER = 'v4.11.2'; + private static final String CURRENT_VERSION_NUMBER = 'v4.11.3'; private static final System.LoggingLevel FALLBACK_LOGGING_LEVEL = System.LoggingLevel.DEBUG; private static final Set IGNORED_APEX_CLASSES = initializeIgnoredApexClasses(); private static final List LOG_ENTRIES_BUFFER = new List(); diff --git a/nebula-logger/core/main/logger-engine/lwc/logger/logger.js b/nebula-logger/core/main/logger-engine/lwc/logger/logger.js index b4a1686e3..e37a96829 100644 --- a/nebula-logger/core/main/logger-engine/lwc/logger/logger.js +++ b/nebula-logger/core/main/logger-engine/lwc/logger/logger.js @@ -6,7 +6,7 @@ import { LightningElement, api } from 'lwc'; import { createLoggerService } from './loggerService'; -const CURRENT_VERSION_NUMBER = 'v4.11.2'; +const CURRENT_VERSION_NUMBER = 'v4.11.3'; export default class Logger extends LightningElement { #loggerService = createLoggerService(); diff --git a/nebula-logger/core/tests/log-management/classes/LoggerEmailSender_Tests.cls b/nebula-logger/core/tests/log-management/classes/LoggerEmailSender_Tests.cls index a0ddb82f4..f6ac0d6eb 100644 --- a/nebula-logger/core/tests/log-management/classes/LoggerEmailSender_Tests.cls +++ b/nebula-logger/core/tests/log-management/classes/LoggerEmailSender_Tests.cls @@ -6,6 +6,17 @@ @SuppressWarnings('PMD.MethodNamingConventions') @IsTest(IsParallel=true) private class LoggerEmailSender_Tests { + @IsTest + static void it_should_indicate_email_deliverability_is_disabled_when_org_limits_exceeded() { + System.OrgLimit singleEmailOrgLimit = OrgLimits.getMap().get('SingleEmail'); + + // Reserve all of the available single email capacity, which is the effectively + // the same as the email limit being exceeded in the org + System.Messaging.reserveSingleEmailCapacity(singleEmailOrgLimit.getLimit()); + + System.Assert.isFalse(LoggerEmailSender.IS_EMAIL_DELIVERABILITY_ENABLED); + } + @IsTest static void it_should_filter_apex_error_recipients() { ApexEmailNotification emailListNotification = new ApexEmailNotification(Email = 'hello@test.com;fake.person@not.real.com.biz', UserId = null); diff --git a/package.json b/package.json index 42ce3eb08..84746b3ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nebula-logger", - "version": "4.11.2", + "version": "4.11.3", "description": "The most robust logger for Salesforce. Works with Apex, Lightning Components, Flow, Process Builder & Integrations. Designed for Salesforce admins, developers & architects.", "author": "Jonathan Gillespie", "license": "MIT", diff --git a/sfdx-project.json b/sfdx-project.json index 22ad79736..f464afa43 100644 --- a/sfdx-project.json +++ b/sfdx-project.json @@ -13,9 +13,9 @@ "package": "Nebula Logger - Core", "path": "./nebula-logger/core", "definitionFile": "./config/scratch-orgs/base-scratch-def.json", - "versionNumber": "4.11.2.NEXT", - "versionName": "New Exception Methods for Apex", - "versionDescription": "Added new method overloads Logger.exception() that automatically log, save, and throw the provided exception", + "versionNumber": "4.11.3.NEXT", + "versionName": "Bugfix for Unhandled Email Exception", + "versionDescription": "Added an extra check in LoggerEmailSender to avoid sending more emails when the org's email limits have been exceeded", "releaseNotesUrl": "https://github.com/jongpie/NebulaLogger/releases", "unpackagedMetadata": { "path": "./nebula-logger/extra-tests" @@ -150,6 +150,7 @@ "Nebula Logger - Core@4.11.0-summer-'23-release": "04t5Y0000023SI6QAM", "Nebula Logger - Core@4.11.1-throw-exception-in-flow-actions": "04t5Y000001TsX4QAK", "Nebula Logger - Core@4.11.2-new-exception-methods-for-apex": "04t5Y000001TsZAQA0", + "Nebula Logger - Core@4.11.3-bugfix-for-unhandled-email-exception": "04t5Y000001HZd0QAG", "Nebula Logger - Core Plugin - Async Failure Additions": "0Ho5Y000000blO4SAI", "Nebula Logger - Core Plugin - Async Failure Additions@1.0.0": "04t5Y0000015lhiQAA", "Nebula Logger - Core Plugin - Async Failure Additions@1.0.1": "04t5Y0000015lhsQAA",