Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment