From cfbe9d2e2fccd09acf0b13a50b5f10c678650876 Mon Sep 17 00:00:00 2001 From: Marci Kickliter Date: Thu, 16 Jul 2020 13:27:24 -0400 Subject: [PATCH 1/2] create task when email handler gets the org-wide email confirm link --- .../RecommendationsInboundEmailHandler.cls | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/force-app/main/default/classes/RecommendationsInboundEmailHandler.cls b/force-app/main/default/classes/RecommendationsInboundEmailHandler.cls index 2ca48021..12e641b3 100644 --- a/force-app/main/default/classes/RecommendationsInboundEmailHandler.cls +++ b/force-app/main/default/classes/RecommendationsInboundEmailHandler.cls @@ -7,10 +7,26 @@ global class RecommendationsInboundEmailHandler implements Messaging.InboundEmai public static final String EMAIL_REPLY_HELP = 'HELP'; public static final Integer RESPONSE_TRUNCATION_LEN = 10; + // key string to find the org-wide email verification link + public static final String CONFIRM_EMAIL_LINK_KEY = 'Click this link to confirm this Organization-Wide Email Address:'; global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) { Messaging.InboundEmailResult result = new Messaging.InboundEmailresult(); - System.debug('RecommendationsInboundEmailHandler received text of email '+email.plainTextBody); + + // create a task for the org-wide email address verification link + if (email.plainTextBody.containsIgnoreCase(CONFIRM_EMAIL_LINK_KEY)) { + // get the running user + Id runningUserId = UserInfo.getUserId(); + + // create the task and assign it to the user + Task confirmTask = new Task(); + confirmTask.Subject = 'Confirm Organization-Wide Email Address'; + confirmTask.Status = 'Open'; + confirmTask.OwnerId = runningUserId; + confirmTask.Description = email.plainTextBody; + + insert confirmTask; + } if (email.plainTextBody.containsIgnoreCase(EMAIL_REFERRAL_RESPONSE_TOKEN)) { // get the referral response id from the body of the reply From ad0a08235cb23d0f3ddf5f24cb10588cb09518ee Mon Sep 17 00:00:00 2001 From: Marci Kickliter Date: Thu, 16 Jul 2020 13:41:17 -0400 Subject: [PATCH 2/2] add a unit test for new code --- .../RecommendationsInboundEmailHandler.cls | 27 +++++++++++-------- ...est_RecommendationsInboundEmailHandler.cls | 16 +++++++++++ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/force-app/main/default/classes/RecommendationsInboundEmailHandler.cls b/force-app/main/default/classes/RecommendationsInboundEmailHandler.cls index 12e641b3..81aee35b 100644 --- a/force-app/main/default/classes/RecommendationsInboundEmailHandler.cls +++ b/force-app/main/default/classes/RecommendationsInboundEmailHandler.cls @@ -15,17 +15,7 @@ global class RecommendationsInboundEmailHandler implements Messaging.InboundEmai // create a task for the org-wide email address verification link if (email.plainTextBody.containsIgnoreCase(CONFIRM_EMAIL_LINK_KEY)) { - // get the running user - Id runningUserId = UserInfo.getUserId(); - - // create the task and assign it to the user - Task confirmTask = new Task(); - confirmTask.Subject = 'Confirm Organization-Wide Email Address'; - confirmTask.Status = 'Open'; - confirmTask.OwnerId = runningUserId; - confirmTask.Description = email.plainTextBody; - - insert confirmTask; + createEmailConfirmTask(email.plainTextBody); } if (email.plainTextBody.containsIgnoreCase(EMAIL_REFERRAL_RESPONSE_TOKEN)) { @@ -111,6 +101,21 @@ global class RecommendationsInboundEmailHandler implements Messaging.InboundEmai } + @TestVisible + private static void createEmailConfirmTask(String emailBody) { + // get the running user + Id runningUserId = UserInfo.getUserId(); + + // create the task and assign it to the user + Task confirmTask = new Task(); + confirmTask.Subject = 'Confirm Organization-Wide Email Address'; + confirmTask.Status = 'Not Started'; + confirmTask.OwnerId = runningUserId; + confirmTask.Description = emailBody; + + insert confirmTask; + } + @TestVisible private static Referral_Response__c getReferralResponse(String referralResponseId) { Referral_Response__c response = new Referral_Response__c(); diff --git a/force-app/main/default/classes/Test_RecommendationsInboundEmailHandler.cls b/force-app/main/default/classes/Test_RecommendationsInboundEmailHandler.cls index b48f9a1d..6d1c7953 100644 --- a/force-app/main/default/classes/Test_RecommendationsInboundEmailHandler.cls +++ b/force-app/main/default/classes/Test_RecommendationsInboundEmailHandler.cls @@ -182,6 +182,22 @@ public class Test_RecommendationsInboundEmailHandler { System.assertEquals('How are you',refRespCheck.Question__c); } + static testMethod void testCreateEmailConfirmTask() { + Test.startTest(); + RecommendationsInboundEmailHandler.createEmailConfirmTask('body of email'); + Test.stopTest(); + + Task confirmTask = [ + SELECT + Id, + Description + FROM Task + WHERE Subject = 'Confirm Organization-Wide Email Address' + ][0]; + + System.assertEquals('body of email', confirmTask.Description); + } + static Referral_Response__c getReferralResponse() { List responses = [ SELECT