Skip to content

Commit

Permalink
Merge pull request #152 from Salesforce-org-Impact-Labs/feature/task-…
Browse files Browse the repository at this point in the history
…for-email-verification

create task when email handler gets the org-wide email confirm link
  • Loading branch information
dragongrrl authored Jul 16, 2020
2 parents 2ef3f66 + ad0a082 commit e69b87d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ 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)) {
createEmailConfirmTask(email.plainTextBody);
}

if (email.plainTextBody.containsIgnoreCase(EMAIL_REFERRAL_RESPONSE_TOKEN)) {
// get the referral response id from the body of the reply
Expand Down Expand Up @@ -95,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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Referral_Response__c> responses = [
SELECT
Expand Down

0 comments on commit e69b87d

Please sign in to comment.