You need to sign in to do that
Don't have an account?
Yuri 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!!
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!!
All Answers