You need to sign in to do that
Don't have an account?
KatherineC
Trigger failed to deploy with 100% code coverage
Hi,
My trigger failed to deploy with 100% code coverage. I got help for creating the trigger and test, don't know why it's only 22% coverage at deployment, please help.
Trigger:
trigger SemiMonthly on Pint__c (after update) {
List<Pint__c> pints = new List<Pint__c>();
for (Pint__c p : Trigger.new) {
if (p.Semi_Monthly__c == true ) {
Pint__c newPint = new Pint__c();
newPint.Account__c = p.Account__c;
pints.add(newPint);
}
}
if(pints.size() > 0) insert pints;
}
Test:
@isTest
public class TestSemiMonthly
{
static testMethod void insertNewPint()
{
// All these records created in your test method are only valid for the tests
// and they do not actually get inserted in the database, nor they're available
// outside this context
Account account = new Account();
account.Name = 'Test Account';
insert account;
Pint__c PintToCreate = new Pint__c();
PintToCreate.Account__c = account.Id; // HERE we need an ID, not a Name
insert PintToCreate;
Test.StartTest();
PintToCreate.Semi_Monthly__c = true;
update PintToCreate;
Test.StopTest();
}
}
Error message:
, Details: Average test coverage across all Apex Classes and Triggers is 22%, at least 75% test coverage is required.
My trigger failed to deploy with 100% code coverage. I got help for creating the trigger and test, don't know why it's only 22% coverage at deployment, please help.
Trigger:
trigger SemiMonthly on Pint__c (after update) {
List<Pint__c> pints = new List<Pint__c>();
for (Pint__c p : Trigger.new) {
if (p.Semi_Monthly__c == true ) {
Pint__c newPint = new Pint__c();
newPint.Account__c = p.Account__c;
pints.add(newPint);
}
}
if(pints.size() > 0) insert pints;
}
Test:
@isTest
public class TestSemiMonthly
{
static testMethod void insertNewPint()
{
// All these records created in your test method are only valid for the tests
// and they do not actually get inserted in the database, nor they're available
// outside this context
Account account = new Account();
account.Name = 'Test Account';
insert account;
Pint__c PintToCreate = new Pint__c();
PintToCreate.Account__c = account.Id; // HERE we need an ID, not a Name
insert PintToCreate;
Test.StartTest();
PintToCreate.Semi_Monthly__c = true;
update PintToCreate;
Test.StopTest();
}
}
Error message:
, Details: Average test coverage across all Apex Classes and Triggers is 22%, at least 75% test coverage is required.
As during deployment of these new components the production estimates overall code coverage by considering new/updated test class.
All Answers
Then modify the test class for the corresponding Apex Class and include modified test class in your package/Change set which you want to deploy.
And if you have some other Apex Classes in your Change Set or package then include their test class with > 75 % coverage also along with trigger and its test class.
As during deployment of these new components the production estimates overall code coverage by considering new/updated test class.