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
Christopher PickingChristopher Picking 

Trigger receives 0% coverage

This is my class, test class, and trigger. When I try to deploy to Production my trigger recieves 0% coverage. I'm a complete beginner and unable to figure this out, your help is greatly apprecitated. 

Class -
public with sharing class TaskTriggerHelper2 {

    public static void assignTaskType(List<Task> newTasks)
    {
        for(Task aTask : newTasks)
        {
            if(aTask.Subject.contains('Obtain Updated ADS Cost from Supplier'))
            {
                aTask.Type = 'Supplier Update Request';
            }
        }
    }
}

Test Class -
@isTest
public with sharing class TaskTriggerHelper2TEST{
    public static testMethod void testTaskTriggerHelper2TEST(){      
        list <task> newTasks = new list <task> ();
        task aTask = new task();
        atask.subject = 'Obtain Updated ADS Cost from Supplier';
        atask.Status = 'Not Started';    
        atask.Priority = 'Normal';
       
        insert newTasks;
    }   
}

Trigger -
trigger Task2 on Task (before insert)
{
if(Trigger.isBefore && Trigger.isInsert)
    {
        TaskTriggerHelper2.assignTaskType(Trigger.new);
    }
}
Best Answer chosen by Christopher Picking
@anilbathula@@anilbathula@
Hi Chris picking 1,

Just try the below test class code:-

@isTest
public with sharing class TaskTriggerHelper2TEST{
    public static testMethod void testTaskTriggerHelper2TEST(){     
        list <task> newTasks = new list <task> ();
        task aTask = new task();
        atask.subject = 'Obtain Updated ADS Cost from Supplier';
        atask.Status = 'Not Started';   
        atask.Priority = 'Normal';

        newTasks.add(atask);   
      
        insert newTasks;
    }  
}


Thanks
Anil.B

All Answers

@anilbathula@@anilbathula@
Hi Chris picking 1,

Just try the below test class code:-

@isTest
public with sharing class TaskTriggerHelper2TEST{
    public static testMethod void testTaskTriggerHelper2TEST(){     
        list <task> newTasks = new list <task> ();
        task aTask = new task();
        atask.subject = 'Obtain Updated ADS Cost from Supplier';
        atask.Status = 'Not Started';   
        atask.Priority = 'Normal';

        newTasks.add(atask);   
      
        insert newTasks;
    }  
}


Thanks
Anil.B
This was selected as the best answer
Christopher PickingChristopher Picking
Perfect, Thanks for the help Anil!