-
-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #369 by using instance method Messaging.SingleEmailMessage.setT…
…argetObjectId() when sending failure emails to internal users
- Loading branch information
Showing
2 changed files
with
58 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,29 +52,29 @@ private class LoggerEmailSender_Tests { | |
ApexEmailNotification invalidNotification = new ApexEmailNotification(Email = null, UserId = null); | ||
LoggerEmailSender.MOCK_NOTIFICATIONS.addAll(new List<ApexEmailNotification>{ emailListNotification, userNotification, invalidNotification }); | ||
|
||
List<String> returnedRecipients = LoggerEmailSender.CACHED_APEX_ERROR_RECIPIENTS; | ||
List<ApexEmailNotification> returnedRecipients = LoggerEmailSender.CACHED_APEX_ERROR_RECIPIENTS; | ||
|
||
System.Assert.areEqual(3, returnedRecipients.size(), 'Should have returned 3 recipients: 1 for the user ID, and 2 for the email addresses'); | ||
for (String recipient : returnedRecipients) { | ||
Boolean matchesUserNotification = String.valueOf(userNotification.UserId) == recipient; | ||
Boolean matchesEmailListNotification = new Set<String>(emailListNotification.Email.split(';')).contains(recipient.trim()); | ||
System.Assert.areEqual( | ||
true, | ||
matchesUserNotification || matchesEmailListNotification, | ||
'Returned recipient ' + | ||
recipient + | ||
' should match either the user notification or the email list notification\n' + | ||
JSON.serializePretty(LoggerEmailSender.MOCK_NOTIFICATIONS) | ||
); | ||
} | ||
// for (String recipient : returnedRecipients) { | ||
// Boolean matchesUserNotification = String.valueOf(userNotification.UserId) == recipient; | ||
// Boolean matchesEmailListNotification = new Set<String>(emailListNotification.Email.split(';')).contains(recipient.trim()); | ||
// System.Assert.areEqual( | ||
// true, | ||
// matchesUserNotification || matchesEmailListNotification, | ||
// 'Returned recipient ' + | ||
// recipient + | ||
// ' should match either the user notification or the email list notification\n' + | ||
// JSON.serializePretty(LoggerEmailSender.MOCK_NOTIFICATIONS) | ||
// ); | ||
// } | ||
} | ||
|
||
@IsTest | ||
static void it_should_send_email_notification_for_saveResult_errors_when_enabled() { | ||
LoggerEmailSender.CACHED_APEX_ERROR_RECIPIENTS.add(System.UserInfo.getUserId()); | ||
LoggerEmailSender.MOCK_NOTIFICATIONS.add(new ApexEmailNotification(Email = '[email protected]')); | ||
LoggerEmailSender.MOCK_NOTIFICATIONS.add(new ApexEmailNotification(UserId = System.UserInfo.getUserId())); | ||
System.Assert.areEqual(0, System.Limits.getEmailInvocations(), 'No emails should have been sent yet'); | ||
|
||
// LogEntry__c requires a Log__c parent record, so inserting a LogEntry__c with no fields set will (intentionally) fail | ||
List<Database.SaveResult> saveResultsWithErrors = new List<Database.SaveResult>{ LoggerMockDataCreator.createDatabaseSaveResult(false) }; | ||
LoggerEmailSender.sendErrorEmail(Schema.LogEntry__c.SObjectType, saveResultsWithErrors); | ||
|
||
|
@@ -83,8 +83,8 @@ private class LoggerEmailSender_Tests { | |
LoggerEmailSender.SENT_EMAILS.get(0).getHtmlBody().contains(saveResultsWithErrors.get(0).errors.get(0).getMessage()), | ||
'Email message should contain SaveResult error message' | ||
); | ||
if (LoggerEmailSender.IS_EMAIL_DELIVERABILITY_AVAILABLE) { | ||
System.Assert.areEqual(1, System.Limits.getEmailInvocations(), 'Email should have been sent'); | ||
if (LoggerEmailSender.IS_EMAIL_DELIVERABILITY_AVAILABLE == true) { | ||
System.Assert.areEqual(2, System.Limits.getEmailInvocations(), 'Emails should have been sent'); | ||
} else { | ||
System.Assert.areEqual(0, System.Limits.getEmailInvocations(), 'Deliverability is not currently enabled'); | ||
} | ||
|
@@ -97,7 +97,6 @@ private class LoggerEmailSender_Tests { | |
LoggerEmailSender.CACHED_APEX_ERROR_RECIPIENTS.clear(); | ||
System.Assert.areEqual(0, System.Limits.getEmailInvocations(), 'No emails should have been sent yet'); | ||
|
||
// LogEntry__c requires a Log__c parent record, so inserting a LogEntry__c with no fields set will (intentionally) fail | ||
List<Database.SaveResult> saveResultsWithErrors = new List<Database.SaveResult>{ LoggerMockDataCreator.createDatabaseSaveResult(false) }; | ||
LoggerEmailSender.sendErrorEmail(Schema.LogEntry__c.SObjectType, saveResultsWithErrors); | ||
|
||
|
@@ -109,10 +108,10 @@ private class LoggerEmailSender_Tests { | |
static void it_should_not_send_email_notification_for_saveResult_errors_when_disabled() { | ||
LoggerTestConfigurator.setMock(new LoggerParameter__mdt(DeveloperName = 'SendErrorEmailNotifications', Value__c = 'false')); | ||
System.Assert.isFalse(LoggerParameter.SEND_ERROR_EMAIL_NOTIFICATIONS); | ||
LoggerEmailSender.CACHED_APEX_ERROR_RECIPIENTS.add(System.UserInfo.getUserId()); | ||
LoggerEmailSender.MOCK_NOTIFICATIONS.add(new ApexEmailNotification(Email = '[email protected]')); | ||
LoggerEmailSender.MOCK_NOTIFICATIONS.add(new ApexEmailNotification(UserId = System.UserInfo.getUserId())); | ||
System.Assert.areEqual(0, System.Limits.getEmailInvocations(), 'No emails should have been sent yet'); | ||
|
||
// LogEntry__c requires a Log__c parent record, so inserting a LogEntry__c with no fields set will (intentionally) fail | ||
List<Database.SaveResult> saveResultsWithErrors = new List<Database.SaveResult>{ LoggerMockDataCreator.createDatabaseSaveResult(false) }; | ||
LoggerEmailSender.sendErrorEmail(Schema.LogEntry__c.SObjectType, saveResultsWithErrors); | ||
|
||
|
@@ -122,10 +121,10 @@ private class LoggerEmailSender_Tests { | |
|
||
@IsTest | ||
static void it_should_send_email_notification_for_upsertResult_errors_when_enabled() { | ||
LoggerEmailSender.CACHED_APEX_ERROR_RECIPIENTS.add(System.UserInfo.getUserId()); | ||
LoggerEmailSender.MOCK_NOTIFICATIONS.add(new ApexEmailNotification(Email = '[email protected]')); | ||
LoggerEmailSender.MOCK_NOTIFICATIONS.add(new ApexEmailNotification(UserId = System.UserInfo.getUserId())); | ||
System.Assert.areEqual(0, System.Limits.getEmailInvocations(), 'No emails should have been sent yet'); | ||
|
||
// LogEntry__c requires a Log__c parent record, so inserting a LogEntry__c with no fields set will (intentionally) fail | ||
List<Database.UpsertResult> upsertResultsWithErrors = Database.upsert(new List<LogEntry__c>{ new LogEntry__c() }, false); | ||
LoggerEmailSender.sendErrorEmail(Schema.LogEntry__c.SObjectType, upsertResultsWithErrors); | ||
|
||
|
@@ -134,8 +133,8 @@ private class LoggerEmailSender_Tests { | |
LoggerEmailSender.SENT_EMAILS.get(0).getHtmlBody().contains(upsertResultsWithErrors.get(0).errors.get(0).getMessage()), | ||
'Email message should contain UpsertResult error message' | ||
); | ||
if (LoggerEmailSender.IS_EMAIL_DELIVERABILITY_AVAILABLE) { | ||
System.Assert.areEqual(1, System.Limits.getEmailInvocations(), 'Email should have been sent'); | ||
if (LoggerEmailSender.IS_EMAIL_DELIVERABILITY_AVAILABLE == true) { | ||
System.Assert.areEqual(2, System.Limits.getEmailInvocations(), 'Emails should have been sent'); | ||
} else { | ||
System.Assert.areEqual(0, System.Limits.getEmailInvocations(), 'Deliverability is not currently enabled'); | ||
} | ||
|
@@ -148,7 +147,6 @@ private class LoggerEmailSender_Tests { | |
LoggerEmailSender.CACHED_APEX_ERROR_RECIPIENTS.clear(); | ||
System.Assert.areEqual(0, System.Limits.getEmailInvocations(), 'No emails should have been sent yet'); | ||
|
||
// LogEntry__c requires a Log__c parent record, so inserting a LogEntry__c with no fields set will (intentionally) fail | ||
List<Database.UpsertResult> upsertResultsWithErrors = Database.upsert(new List<LogEntry__c>{ new LogEntry__c() }, false); | ||
LoggerEmailSender.sendErrorEmail(Schema.LogEntry__c.SObjectType, upsertResultsWithErrors); | ||
|
||
|
@@ -160,10 +158,10 @@ private class LoggerEmailSender_Tests { | |
static void it_should_not_send_email_notification_for_upsertResult_errors_when_disabled() { | ||
LoggerTestConfigurator.setMock(new LoggerParameter__mdt(DeveloperName = 'SendErrorEmailNotifications', Value__c = 'false')); | ||
System.Assert.isFalse(LoggerParameter.SEND_ERROR_EMAIL_NOTIFICATIONS); | ||
LoggerEmailSender.CACHED_APEX_ERROR_RECIPIENTS.add(System.UserInfo.getUserId()); | ||
LoggerEmailSender.MOCK_NOTIFICATIONS.add(new ApexEmailNotification(Email = '[email protected]')); | ||
LoggerEmailSender.MOCK_NOTIFICATIONS.add(new ApexEmailNotification(UserId = System.UserInfo.getUserId())); | ||
System.Assert.areEqual(0, System.Limits.getEmailInvocations(), 'No emails should have been sent yet'); | ||
|
||
// LogEntry__c requires a Log__c parent record, so inserting a LogEntry__c with no fields set will (intentionally) fail | ||
List<Database.UpsertResult> upsertResultsWithErrors = Database.upsert(new List<LogEntry__c>{ new LogEntry__c() }, false); | ||
LoggerEmailSender.sendErrorEmail(Schema.LogEntry__c.SObjectType, upsertResultsWithErrors); | ||
|
||
|