function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SeanCenoSeanCeno 

After adding Trigger.OldMap, 0% Test Coverage

All,
I have a requirement to update a trigger to include Trigger.OldMap so that if a user edits a completed task, it doesn't fire the trigger again. Once I added Trigger.OldMap to the trigger, my test coverage went from 95% to 0%. Adding an Update to the inserted Task in the test code does not seem to help either. Below is my code:

Trigger:
trigger SalesBlitzProcess on Task (after insert, after update) {
    if(!RecursiveTriggerHelper.isAlreadyModified()){
        RecursiveTriggerHelper.setAlreadyModified();{
            Task[] taskOldList = trigger.IsDelete ? null : trigger.old;
            Task[] taskNewList = trigger.IsDelete ? trigger.old : trigger.new;
            if(trigger.oldMap != null) {
                for(task tsk: trigger.new) {
                    if(tsk.isClosed && trigger.oldMap.get(tsk.Id).isClosed == false){
                        new SalesBlitzProcess(trigger.Old, trigger.New).executeLeftMessage();
                        new SalesBlitzProcess(trigger.Old, trigger.New).executeContinueProcess();
                        new SalesBlitzProcess(trigger.Old, trigger.New).executeNotNow();
                        new SalesBlitzProcess(trigger.Old, trigger.New).executeHardNo();
                    }
                }
            }
        }
    }
}



Class
public class SalesBlitzProcess {
    //Grab List of tasks
    protected final Task[] taskNewList;
    protected final Task[] taskOldList;
    
    public SalesBlitzProcess (Task[] taskOldList, Task[] taskNewList){
        this.taskNewList = taskNewList;
        this.taskOldList = taskOldList;
    }
    
    List<Task> taskList = new List<Task>();
    List<Opportunity> oppList = new List<Opportunity>();
    Task t;
    Opportunity o;
    Contact c;
    Account a;
    
    //Left Message - Create new Tasks if the following Outcomes == 'Left Message' || 'No Answer'
    Set<Contact> cSet = new Set<Contact>();
    public void executeLeftMessage(){
        for(Task tsk : taskNewList){
            if(tsk.Status =='Completed' && tsk.Subject == 'Sales Blitz Call - Day 1' && (tsk.Outcome__c == 'Left Message' || tsk.Outcome__c == 'No Answer')){
                //Set c.Nurture_Paused__c = True; and c.Send_Day_1_Follow_Up_Email__c = true;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Nurture_Paused__c = true;
                    c.Send_Day_1_Follow_Up_Email__c = true;
                    cSet.add(c);
                }
                t = new Task();
                t.OwnerId = tsk.OwnerId;
                t.WhoId = tsk.WhoId;
                t.Subject = 'Sales Blitz Call - Day 3';
                t.Status = 'Not Started';
                t.ActivityDate = System.Today().addDays(2);
                taskList.add(t);
                
            } else if (tsk.Status =='Completed' && tsk.Subject == 'Sales Blitz Call - Day 3' && (tsk.Outcome__c == 'Left Message' || tsk.Outcome__c == 'No Answer')){
                t = new Task();
                t.OwnerId = tsk.OwnerId;
                t.WhoId = tsk.WhoId;
                t.Subject = 'Sales Blitz Call - Day 5';
                t.Status = 'Not Started';
                t.ActivityDate = System.Today().addDays(2);
                taskList.add(t);
                
            } else if (tsk.Status =='Completed' && tsk.Subject == 'Sales Blitz Call - Day 5' && (tsk.Outcome__c == 'Left Message' || tsk.Outcome__c == 'No Answer')){
                //c.Send_Day_1_Follow_Up_Email__c = true;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Send_Day_5_Follow_Up_Email__c = true;
                    cSet.add(c);
                }
                t = new Task();
                t.OwnerId = tsk.OwnerId;
                t.WhoId = tsk.WhoId;
                t.Subject = 'Sales Blitz Call - Day 8';
                t.Status = 'Not Started';
                t.ActivityDate = System.Today().addDays(3);
                taskList.add(t);
                
            } else if (tsk.Status =='Completed' && tsk.Subject == 'Sales Blitz Call - Day 8' && (tsk.Outcome__c == 'Left Message' || tsk.Outcome__c == 'No Answer')){
                //Set c.Nurture_Paused__c = False;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Nurture_Paused__c = false;
                    c.Send_Day_1_Follow_Up_Email__c = false;
                    c.Send_Day_5_Follow_Up_Email__c = false;
                    cSet.add(c);
                }
            }
        }
        
        If(!taskList.isEmpty()){
            insert taskList;
        }
        If(!cSet.isEmpty()){
            update new List <Contact>(cSet);
        }
    }
    
    //Continue Process - Create Opportunity if Task has the following outcomes
    Set<Id> ContactIds = new Set<Id>();
    public void executeContinueProcess(){
        for(Task tsk : taskNewList){
            if(tsk.Status =='Completed' && (tsk.Outcome__c == 'Set First Advisor Briefing'
                                            || tsk.Outcome__c == 'Set Qualified Meeting'
                                            || tsk.Outcome__c == 'Set Existing Producer Meeting'
                                            || tsk.Outcome__c == 'Set Touch Base Meeting'
                                            || tsk.Outcome__c == 'Proposal Needed'
                                            || tsk.Outcome__c == 'Verbal Commitment')){
                                                String tId = tsk.WhoId;
                                                if(String.ValueOf(tsk.WhoId).substring(0,3) == '003'){
                                                    ContactIds.add(tsk.WhoId);
                                                }
                                            }
        }
        if(!ContactIds.isEmpty())
        {
            Map<Id, Contact> cIdMap = new Map<Id, Contact>([Select Id, AccountId, Account.Name, Nurture_Paused__c FROM Contact Where Id in:ContactIds]);
            Set<Id> accountIds=new Set<Id>();
            for(Task tsk : taskNewList)
            {
                if(tsk.WhoId != null && cIdMap.get(tsk.WhoId) != null){
                    //o.AccountId = cIdMap.get(tsk.WhoId).AccountId;
                    accountIds.add(cIdMap.get(tsk.WhoId).AccountId);
                }
            }
            
            if(!accountIds.isEmpty())
            {
                Map<Id,Account> mapAccount=new Map<Id,Account>([SELECT Id, (SELECT Id FROM Opportunities) FROM Account where Id IN : accountIds]);
                for(Id accId:accountIds)
                {
                    if(mapAccount.containsKey(accId))
                    {
                        if(mapAccount.get(accId).Opportunities.size() == 0)
                        {
                            Opportunity opp=new Opportunity();
                            opp.Name = 'New Sales Blitz Opportunity';
                            opp.AccountId = accId;
                            opp.StageName = 'New';
                            opp.Opportunity_Potential__c = 0.00;
                            opp.CloseDate = Date.today();
                            opp.OriginalOpportunitySource__c = 'Sales Blitz';
                            oppList.add(opp);
                        }
                    }
                }
                
            }
        }
        If(!oppList.isEmpty()){
            insert oppList;
        }
    }
    
    //Not Now - Check Nurture Paused for 3 weeks if Outcome__c == Follow Up Or TBD, then unpause.
    public void executeNotNow(){
        for(Task tsk : taskNewList){
            if(tsk.Status =='Completed' && (tsk.Outcome__c == 'Follow Up' || tsk.Outcome__c == 'TBD')){
                //Set c.Nurture_Paused__c = True;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Nurture_Paused__c = true;
                    cSet.add(c);
                }
                t = new Task();
                t.OwnerId = '005F0000004E8iS';
                t.WhoId = tsk.WhoId;
                t.Subject = 'Unpause Nurture - 3 Weeks';
                t.Status = 'Not Started';
                t.Outcome__c = 'Unpause Nurture';
                t.ActivityDate = System.Today().addDays(21);
                taskList.add(t);
            }
            //After 3 weeks, unpause nurture
            //Once closed, uncheck checkbox
            else if (tsk.Status =='Completed' && tsk.Subject == 'Unpause Nurture - 3 Weeks' && tsk.Outcome__c == 'Unpause Nurture'){
                //Set c.Nurture_Paused__c = False;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Nurture_Paused__c = false;
                    cSet.add(c);
                }
            }
        }
        If(!taskList.isEmpty()){
            insert t;
        }
        if(!cSet.isEmpty()){
            update new List <Contact>(cSet);
        }
    }
    //Hard No - Create reminder task to close in 90 days to unpause nurture
    public void executeHardNo(){
        for(Task tsk : taskNewList){
            if(tsk.Status =='Completed' && tsk.Outcome__c == 'Not Interested' && tsk.Subject.contains('Sales Blitz')){
                //Set c.Nurture_Paused__c = True;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Nurture_Paused__c = true;
                    cSet.add(c);
                }
                t = new Task();
                t.OwnerId = '005F0000004E8iS';
                t.WhoId = tsk.WhoId;
                t.Subject = 'Unpause Nurture - 3 Months';
                t.Status = 'Not Started';
                t.Outcome__c = 'Unpause Nurture';
                t.ActivityDate = System.Today().addDays(90);
                taskList.add(t);
            }
            //After 3 months, unpause nurture
            //Once closed, uncheck checkbox
            else if (tsk.Status =='Completed' && tsk.Subject == 'Unpause Nurture - 3 Months' && tsk.Outcome__c == 'Unpause Nurture'){
                //Set c.Nurture_Paused__c = False;
                if(tsk.WhoId != null && String.valueOf(tsk.whoId).substring(0,3) == '003') {
                    c = new Contact(Id = tsk.whoId);
                    c.Nurture_Paused__c = false;
                    cSet.add(c);
                }
            }
        }
        If(!taskList.isEmpty()){
            insert t;
        }
        if(!cSet.isEmpty()){
            update new List <Contact>(cSet);
        }
    }
}

Test Class
@isTest
private class testSalesBlitzProcess {
    
    static testMethod void LeftMessage1(){
        Profile p=[SELECT Id From Profile WHERE Name='Standard User'];
        User u =new User(Alias = 'newUser' , Email ='testuser@361capital.com' , EmailEncodingKey = 'UTF-8' , LastName = 'Testing',
                         LanguageLocaleKey='en_US', LocaleSidKey='en_US', TimeZoneSidKey = 'GMT', UserName='testuser@361capital.com',ProfileId=p.Id);
        insert u;
        
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = u.id;
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Sales Blitz Call - Day 1';
        tsk.Outcome__c = 'Left Message';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(1);
        insert tsk;
    }
    
        static testMethod void LeftMessage1TESTNULL(){
        Profile p=[SELECT Id From Profile WHERE Name='Standard User'];
        User u =new User(Alias = 'newUser' , Email ='testuser@361capital.com' , EmailEncodingKey = 'UTF-8' , LastName = 'Testing',
                         LanguageLocaleKey='en_US', LocaleSidKey='en_US', TimeZoneSidKey = 'GMT', UserName='testuser@361capital.com',ProfileId=p.Id);
        insert u;
        
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = u.id;
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Sales Blitz Call - Day 1';
        tsk.Outcome__c = 'Left Message';
        tsk.Status = null;
        tsk.ActivityDate = System.Today().addDays(1);
        insert tsk;
        
        test.startTest();
        tsk.Status='Completed';
        update tsk;
        test.stopTest();
        
         System.assertEquals(tsk.Status = 'Completed', null);
    }
    
    static testMethod void LeftMessage2(){
        Profile p=[SELECT Id From Profile WHERE Name='Standard User'];
        User u =new User(Alias = 'newUser' , Email ='testuser@361capital.com' , EmailEncodingKey = 'UTF-8' , LastName = 'Testing',
                         LanguageLocaleKey='en_US', LocaleSidKey='en_US', TimeZoneSidKey = 'GMT', UserName='testuser@361capital.com',ProfileId=p.Id);
        insert u;
        
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = u.id;
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Sales Blitz Call - Day 3';
        tsk.Outcome__c = 'Left Message';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(1);
        insert tsk;
    }
    
    static testMethod void LeftMessage3(){
        Profile p=[SELECT Id From Profile WHERE Name='Standard User'];
        User u =new User(Alias = 'newUser' , Email ='testuser@361capital.com' , EmailEncodingKey = 'UTF-8' , LastName = 'Testing',
                         LanguageLocaleKey='en_US', LocaleSidKey='en_US', TimeZoneSidKey = 'GMT', UserName='testuser@361capital.com',ProfileId=p.Id);
        insert u;
        
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = u.id;
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Sales Blitz Call - Day 5';
        tsk.Outcome__c = 'Left Message';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(1);
        insert tsk;
    }
    
    static testMethod void LeftMessage4(){
        Profile p=[SELECT Id From Profile WHERE Name='Standard User'];
        User u =new User(Alias = 'newUser' , Email ='testuser@361capital.com' , EmailEncodingKey = 'UTF-8' , LastName = 'Testing',
                         LanguageLocaleKey='en_US', LocaleSidKey='en_US', TimeZoneSidKey = 'GMT', UserName='testuser@361capital.com',ProfileId=p.Id);
        insert u;
        
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = u.id;
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Sales Blitz Call - Day 8';
        tsk.Outcome__c = 'Left Message';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(1);
        insert tsk;
    }
    
    static testMethod void notNow1(){
        Profile p=[SELECT Id From Profile WHERE Name='Standard User'];
        User u =new User(Alias = 'newUser' , Email ='testuser@361capital.com' , EmailEncodingKey = 'UTF-8' , LastName = 'Testing',
                         LanguageLocaleKey='en_US', LocaleSidKey='en_US', TimeZoneSidKey = 'GMT', UserName='testuser@361capital.com',ProfileId=p.Id);
        insert u;
        
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = u.id;
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Unpause Nurture - 3 Weeks';
        tsk.Outcome__c = 'Follow Up';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(21);
        insert tsk;
    }
    
    static testMethod void notNow2(){
        Profile p=[SELECT Id From Profile WHERE Name='Standard User'];
        User u =new User(Alias = 'newUser' , Email ='testuser@361capital.com' , EmailEncodingKey = 'UTF-8' , LastName = 'Testing',
                         LanguageLocaleKey='en_US', LocaleSidKey='en_US', TimeZoneSidKey = 'GMT', UserName='testuser@361capital.com',ProfileId=p.Id);
        insert u;
        
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = u.id;
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Unpause Nurture - 3 Weeks';
        tsk.Outcome__c = 'TBD';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(21);
        insert tsk;
    }
    
    static testMethod void notNow3(){
        Profile p=[SELECT Id From Profile WHERE Name='Standard User'];
        User u =new User(Alias = 'newUser' , Email ='testuser@361capital.com' , EmailEncodingKey = 'UTF-8' , LastName = 'Testing',
                         LanguageLocaleKey='en_US', LocaleSidKey='en_US', TimeZoneSidKey = 'GMT', UserName='testuser@361capital.com',ProfileId=p.Id);
        insert u;
        
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = u.id;
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Unpause Nurture - 3 Weeks';
        tsk.Outcome__c = 'Unpause Nurture';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(21);
        insert tsk;
    }
    
    static testMethod void HardNo1(){
        Profile p=[SELECT Id From Profile WHERE Name='Standard User'];
        User u =new User(Alias = 'newUser' , Email ='testuser@361capital.com' , EmailEncodingKey = 'UTF-8' , LastName = 'Testing',
                         LanguageLocaleKey='en_US', LocaleSidKey='en_US', TimeZoneSidKey = 'GMT', UserName='testuser@361capital.com',ProfileId=p.Id);
        insert u;
        
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = u.id;
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Unpause Nurture - 3 Months';
        tsk.Outcome__c = 'Not Interested';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(21);
        insert tsk;
    }
        static testMethod void HardNo2(){
        Profile p=[SELECT Id From Profile WHERE Name='Standard User'];
        User u =new User(Alias = 'newUser' , Email ='testuser@361capital.com' , EmailEncodingKey = 'UTF-8' , LastName = 'Testing',
                         LanguageLocaleKey='en_US', LocaleSidKey='en_US', TimeZoneSidKey = 'GMT', UserName='testuser@361capital.com',ProfileId=p.Id);
        insert u;
        
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = u.id;
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Unpause Nurture - 3 Months';
        tsk.Outcome__c = 'Unpause Nurture';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(21);
        insert tsk;
    }
    
    static testMethod void testOpportunity1(){
        //Create Account
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = '005F0000003KmQ0';
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Create Opportunity';
        tsk.Outcome__c = 'Set First Advisor Briefing';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(1);
        insert tsk;
        
        //Create Opportunity
        Opportunity oppt = new Opportunity();
        oppt.AccountId = testAcct.Id;
        oppt.Name = 'New Opportunity Name';
        oppt.Opportunity_Potential__c = 100.00;
        oppt.StageName = 'New';
        oppt.Amount = 5000;
        oppt.CloseDate = System.Today();
        insert oppt;
    }
    
    static testMethod void testOpportunity2(){
        //Create Account
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = '005F0000003KmQ0';
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Create Opportunity';
        tsk.Outcome__c = 'Set Qualified Meeting';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(1);
        insert tsk;
        
        //Create Opportunity
        Opportunity oppt = new Opportunity();
        oppt.AccountId = testAcct.Id;
        oppt.Name = 'New Opportunity Name';
        oppt.Opportunity_Potential__c = 100.00;
        oppt.StageName = 'New';
        oppt.Amount = 5000;
        oppt.CloseDate = System.Today();
        insert oppt;
    }
    
    static testMethod void testOpportunity3(){
        //Create Account
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = '005F0000003KmQ0';
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Create Opportunity';
        tsk.Outcome__c = 'Set Existing Producer Meeting';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(1);
        insert tsk;
        
        //Create Opportunity
        Opportunity oppt = new Opportunity();
        oppt.AccountId = testAcct.Id;
        oppt.Name = 'New Opportunity Name';
        oppt.Opportunity_Potential__c = 100.00;
        oppt.StageName = 'New';
        oppt.Amount = 5000;
        oppt.CloseDate = System.Today();
        insert oppt;
    }
    
    static testMethod void testOpportunity4(){
        //Create Account
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = '005F0000003KmQ0';
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Create Opportunity';
        tsk.Outcome__c = 'Set Touch Base Meeting';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(1);
        insert tsk;
        
        //Create Opportunity
        Opportunity oppt = new Opportunity();
        oppt.AccountId = testAcct.Id;
        oppt.Name = 'New Opportunity Name';
        oppt.Opportunity_Potential__c = 100.00;
        oppt.StageName = 'New';
        oppt.Amount = 5000;
        oppt.CloseDate = System.Today();
        insert oppt;
    }
    
    static testMethod void testOpportunity5(){
        //Create Account
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = '005F0000003KmQ0';
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Create Opportunity';
        tsk.Outcome__c = 'Proposal Needed';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(1);
        insert tsk;
        
        //Create Opportunity
        Opportunity oppt = new Opportunity();
        oppt.AccountId = testAcct.Id;
        oppt.Name = 'New Opportunity Name';
        oppt.Opportunity_Potential__c = 100.00;
        oppt.StageName = 'New';
        oppt.Amount = 5000;
        oppt.CloseDate = System.Today();
        insert oppt;
    }
    
    static testMethod void testOpportunity6(){
        //Create Account
        Account testAcct = new Account (Name = 'My Test Account');
        insert testAcct;
        
        Contact testCont = new Contact();
        testCont.FirstName = 'Test';
        testCont.LastName = 'User';
        testCont.AccountId = testAcct.Id;
        insert testCont;
        
        Task tsk = new Task();
        tsk.OwnerId = '005F0000003KmQ0';
        tsk.WhoId = testCont.Id;
        tsk.Subject = 'Create Opportunity';
        tsk.Outcome__c = 'Verbal Commitment';
        tsk.Status = 'Completed';
        tsk.ActivityDate = System.Today().addDays(1);
        insert tsk;
        
        //Create Opportunity
        Opportunity oppt = new Opportunity();
        oppt.AccountId = testAcct.Id;
        oppt.Name = 'New Opportunity Name';
        oppt.Opportunity_Potential__c = 100.00;
        oppt.StageName = 'New';
        oppt.Amount = 5000;
        oppt.CloseDate = System.Today();
        insert oppt;
    }
}
Best Answer chosen by SeanCeno
Suraj PSuraj P
Use this code in your trigger
<pre>
trigger SalesBlitzProcess on Task (after insert, after update) {
    if(!RecursiveTriggerHelper.isAlreadyModified()){
        RecursiveTriggerHelper.setAlreadyModified();
                for(task tsk: trigger.new) {
                    if(Trigger.isInsert || tsk.IsClosed==false || Trigger.oldMap.get(tsk.Id).isClosed==false){
                        new SalesBlitzProcess(trigger.Old, trigger.New).executeLeftMessage();
                        new SalesBlitzProcess(trigger.Old, trigger.New).executeContinueProcess();
                        new SalesBlitzProcess(trigger.Old, trigger.New).executeNotNow();
                        new SalesBlitzProcess(trigger.Old, trigger.New).executeHardNo();
                    }
                }
    }
}
</pre>



Note: You're not really using the Trigger.old anywhere. No need to pass it as an argument into the methods.

All Answers

Suraj PSuraj P
Use this code in your trigger
<pre>
trigger SalesBlitzProcess on Task (after insert, after update) {
    if(!RecursiveTriggerHelper.isAlreadyModified()){
        RecursiveTriggerHelper.setAlreadyModified();
                for(task tsk: trigger.new) {
                    if(Trigger.isInsert || tsk.IsClosed==false || Trigger.oldMap.get(tsk.Id).isClosed==false){
                        new SalesBlitzProcess(trigger.Old, trigger.New).executeLeftMessage();
                        new SalesBlitzProcess(trigger.Old, trigger.New).executeContinueProcess();
                        new SalesBlitzProcess(trigger.Old, trigger.New).executeNotNow();
                        new SalesBlitzProcess(trigger.Old, trigger.New).executeHardNo();
                    }
                }
    }
}
</pre>



Note: You're not really using the Trigger.old anywhere. No need to pass it as an argument into the methods.
This was selected as the best answer
SeanCenoSeanCeno
Thank you, Suraj. Glad it was something simple, and I corrected the Trigger.old as well!