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
Yuri SingidasYuri Singidas 

why my before-delete trigger gets 0% code coverage in production while it's always 40% coverage in the sandbox, preventing me from deploying?

I got frustrated trying to deploy a simple before-delete trigger because it doesn't matter if the code coverage for the trigger is 40% in the sandbox (you only need 1% for triggers) because in production it always drops down to 0% and I cannot deploy it.

I ran all test classes in both production and sandbox environment and they have 94% and 84% code coverage, respectively. What went wrong? The trigger is so simple:

A. Trigger

trigger deleteAppeal on Appeal__c (before delete) 
  {
     Profile userProfile = [ SELECT Name FROM Profile WHERE Id = :UserInfo.getProfileId() ];
     if ( userProfile.Name <> 'SYSTEM ADMINISTRATOR' )
     {
        for ( Appeal__c appeal:trigger.old )
        {
           appeal.addError('You cannot delete an Appeal. Please ask your System Administrator to do it for you.');
        
        }
       
     }
    }

B. Test class:

@isTest
private class DeleteAppealTriggerTest
{   
    
        
    

    static testMethod void deleteAppealTest()
    {
          
    Case tmpDocket = new Case();
    tmpDocket.Date_Of_Claim__c = Date.newInstance( 2014, 4, 6 ); // MUST be a sunday for validation
    insert tmpDocket;

    Appeal__c tmpAppeal = new Appeal__c();
    tmpAppeal.Case__c = tmpDocket.Id;
            
        insert tmpAppeal;

        Test.startTest();
        
        try
        {
            delete tmpAppeal;
         }
         catch(Exception e) 
     {
         system.assertEquals('Appeal cannot be deleted.', e.getMessage());
         }

        Test.stopTest();

        
      }
    
    
}


HELP!!
 
Best Answer chosen by Yuri Singidas
Amit Chaudhary 8Amit Chaudhary 8
Are you deploying test class with Trigger as well ?
 

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Are you deploying test class with Trigger as well ?
 
This was selected as the best answer
Yuri SingidasYuri Singidas
Duh...thanks, Amit. How could I forget to deploy the test class Makes sense why I get 0% code coverage when I try to validate the trigger in the change set. :)