• Yuri Singidas
  • NEWBIE
  • 10 Points
  • Member since 2017
  • Software developer
  • OIT

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
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!!
 
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!!
 
Trying to deploy development from my sandbox using change sets. Whilst custom fields, tabs etc come across fine, the triggers are failing with the following error:

Code Coverage Failure Your organization's code coverage is 0%. You need at least 75% coverage to complete this deployment. Also, the following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.

This means nothing to me and I'm just getting more confused looking through the help documents. I don't really do code and I don't know where to start. Any help would be very much appreciated