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 for 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;

    }
}

 
Best Answer chosen by Brandon Wermes
Mike ArthurMike Arthur
Are you viewing the code coverage in the dev console?

I recently had the same, code coverage in dev console was showing as 0%.  If you check from the UI it shows as, hopefully, 100%. Go to settings, develop, apex test execution and it shows the actual coverage. In dev console it shows 0.

I was able to go ahead and deploy.

Must be a bug somewhere.

All Answers

Mike ArthurMike Arthur
Are you viewing the code coverage in the dev console?

I recently had the same, code coverage in dev console was showing as 0%.  If you check from the UI it shows as, hopefully, 100%. Go to settings, develop, apex test execution and it shows the actual coverage. In dev console it shows 0.

I was able to go ahead and deploy.

Must be a bug somewhere.
This was selected as the best answer
Brandon WermesBrandon Wermes
Thanks Mike. I attempted to deploy but ran into the following error on Production Validation.
Methods defined as TestMethod do not support Web service callouts 
Stack Trace: null

I don't see that the Apex Class is making a Web Service call, so I'm at a loss.