Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
TaskTriggerHandler Test
// Test for the TaskTriggerHandler.
private class TaskTriggerHandler_Test {
//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?',;
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?'];
//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