Skip to content

Commit

Permalink
Bugfix for unhandled exception when email limits are reached (#548)
Browse files Browse the repository at this point in the history
* Added catch for System.HandledException in LoggerEmailSender.cls to avoid trying to send emails when the org's single email limit has been exceeded
  • Loading branch information
patrick-skamarak authored Sep 19, 2023
1 parent a08e1d6 commit 41e6594
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 12 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion nebula-logger/core/main/logger-engine/classes/Logger.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> IGNORED_APEX_CLASSES = initializeIgnoredApexClasses();
private static final List<LogEntryEventBuilder> LOG_ENTRIES_BUFFER = new List<LogEntryEventBuilder>();
Expand Down
2 changes: 1 addition & 1 deletion nebula-logger/core/main/logger-engine/lwc/logger/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[email protected];[email protected]', UserId = null);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 4 additions & 3 deletions sfdx-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -150,6 +150,7 @@
"Nebula Logger - [email protected]'23-release": "04t5Y0000023SI6QAM",
"Nebula Logger - [email protected]": "04t5Y000001TsX4QAK",
"Nebula Logger - [email protected]": "04t5Y000001TsZAQA0",
"Nebula Logger - [email protected]": "04t5Y000001HZd0QAG",
"Nebula Logger - Core Plugin - Async Failure Additions": "0Ho5Y000000blO4SAI",
"Nebula Logger - Core Plugin - Async Failure [email protected]": "04t5Y0000015lhiQAA",
"Nebula Logger - Core Plugin - Async Failure [email protected]": "04t5Y0000015lhsQAA",
Expand Down

0 comments on commit 41e6594

Please sign in to comment.