Skip to content

Instantly share code, notes, and snippets.

@forcethesales
Last active February 14, 2020 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save forcethesales/a92526f043ac65d1dfe09f985d2c5360 to your computer and use it in GitHub Desktop.
Save forcethesales/a92526f043ac65d1dfe09f985d2c5360 to your computer and use it in GitHub Desktop.
TaskTriggerHandler Test
// 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.
}
}