Last active
February 14, 2020 11:04
-
-
Save forcethesales/a92526f043ac65d1dfe09f985d2c5360 to your computer and use it in GitHub Desktop.
TaskTriggerHandler Test
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
// Test for the TaskTriggerHandler. | |
@isTest | |
private class TaskTriggerHandler_Test { | |
//Scenario: | |
//The goal is to test what happens when an email is sent through Salesforce. | |
//Simulate this in the test by creating a task with Subject that starts with 'Email:' on a contact | |
//Expected Result: | |
//New Follow up Task created and attached to contact | |
static testMethod void createEmailTask() { | |
Contact newman = new Contact (LastName='Newman'); | |
insert newman; | |
Task newEmail = new Task (Subject = 'Email: Dude, where is my car?', WhoId=newman.id); | |
insert newEmail; | |
//check that the follow up task exists | |
List <Task> task_afteremail = [SELECT Subject, WhoId, ActivityDate FROM Task WHERE WhoId = :newman.Id AND Subject = 'Follow Up on: Email: Dude, where is my car?']; | |
system.assert(task_afteremail.size()==1); | |
//TODO: Other tests to try: cover the situations when we do NOT want a task created, also when many emails at once are created. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Apex Test Class https://gist.github.com/forcethesales/a92526f043ac65d1dfe09f985d2c5360
Trigger Handler https://gist.github.com/forcethesales/0e2e39a1ed74119eac5dbcdc23f8de99
Task Trigger https://gist.github.com/forcethesales/337b0fbeceefffa89176592effbbdd47