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
Brandon WermesBrandon Wermes 

Lack of Code Coverage on Task Trigger

Hello,

I am working to build a trigger that updates an Opportunity when a Task is added to the opportunity. The trigger is successful in the Sandbox, however my Apex Class to test the trigger is presenting 0% code coverage. I am new to Apex and more of a "Desktop Admin" so any help would be appreciated.

The Trigger:
trigger OptyUpdateonTaskInsert on Task (after insert, after update)
{
    List<Opportunity> lstOpty = new List<Opportunity>();
    for(Task T : Trigger.New)
    {
        if(T.WhatId != null && string.valueof(T.WhatId).startsWith('006'))
        {
            Opportunity opt = new Opportunity(id=T.WhatId);
            lstOpty.add(opt);
        }
    }
    
    update lstOpty;
}
The Class:
 
@isTest(seealldata=true)
public class testTask{
    private static testmethod void testTaskActivity(){
        
        Opportunity o = new Opportunity(
        				AccountId 	= 	'0015500000AByHM',
            			Name 		=	'Test 2',
            			StageName	=	'Proposal Review',
            			CloseDate	=	(System.now()).date(),
            			Type		=	'New System');
        insert o;
                   
        Task t = new Task(
            			WhatId 		= 	o.Id, 
                        Subject 	= 	'Sample Email', 
                        Priority 	= 	'Normal', 
                        Status 		= 	'Completed',
            			OwnerId 	=	UserInfo.getUserId());
        insert t;

    }
}

Thank you very much for assistance.