You need to sign in to do that
Don't have an account?

Code Coverage issue in Trigger calling Class
Hello,
I have a trigger that is not not reaching the 75% threshold.
I have 2 lines of code where I am calling another Class. Any help would be greatly appreciated.
I have a trigger that is not not reaching the 75% threshold.
I have 2 lines of code where I am calling another Class. Any help would be greatly appreciated.
trigger warrantyValueCalculation on Warranties_and_Surveys__c (before insert, before update) { for (Warranties_and_Surveys__c warRec: trigger.new) { if((trigger.isInsert) && (warRec.Warranty_Survey_Account__c=='123' || warRec.Warranty_Survey_Account__c=='456' || warRec.Warranty_Survey_Account__c=='789' || warRec.Warranty_Survey_Account__c=='136' || warRec.Warranty_Survey_Account__c=='764' || warRec.Warranty_Survey_Account__c=='111')&&(warRec.Project_Country__c=='US')){ warrantyAmountCalculation.beforeInsert(trigger.new); ---no coverage } //if((trigger.isUpdate) && ((trigger.oldMap.get(warRec.Id).Registration_Status__c == 'Registered') && (warRec.Registration_Status__c == 'Registered'))){ if((trigger.isUpdate) && (warRec.Warranty_Survey_Account__c=='001f100001M2FVP' || warRec.Warranty_Survey_Account__c=='876' || warRec.Warranty_Survey_Account__c=='590' || warRec.Warranty_Survey_Account__c=='327' || warRec.Warranty_Survey_Account__c=='970' || warRec.Warranty_Survey_Account__c=='327')&&(warRec.Project_Country__c=='US')){ warrantyAmountCalculation.beforeInsert(trigger.new); ---no coverage } } }
trigger warrantyValueCalculation on Warranties_and_Surveys__c (before insert, before update) {
if (Trigger.isInsert)
{
for (Warranties_and_Surveys__c warRec: trigger.new)
{
if(warRec.Warranty_Survey_Account__c=='123' || warRec.Warranty_Survey_Account__c=='456' || warRec.Warranty_Survey_Account__c=='789' || warRec.Warranty_Survey_Account__c=='136' || warRec.Warranty_Survey_Account__c=='764' || warRec.Warranty_Survey_Account__c=='111')&&(warRec.Project_Country__c=='US')){
warrantyAmountCalculation.beforeInsert(trigger.new);
}
}
}
else if(Trigger.isUpdate)
{
for (Warranties_and_Surveys__c warRec: trigger.new)
{
if((warRec.Warranty_Survey_Account__c=='001f100001M2FVP' || warRec.Warranty_Survey_Account__c=='876' || warRec.Warranty_Survey_Account__c=='590' || warRec.Warranty_Survey_Account__c=='327' || warRec.Warranty_Survey_Account__c=='970' || warRec.Warranty_Survey_Account__c=='327')&&(warRec.Project_Country__c=='US')){
warrantyAmountCalculation.beforeInsert(trigger.new);
}
}
}
}
Thanks,
Maharajan.C
All Answers
Do following if you haven't done:
Write test class for trigger and create test data using @TestSetup.
insert and update atleast 20 records.
Make sure you are passing list parameter in beforeInsert method.
Make sure you are not using any custom setting in beforeInsert method..
Use asertions properly.
Thanks
Please use the test class like below:
private class TestClassChatterPosts {
static testMethod void testWarrantiesSurveyonInsert()
{
Warranties_and_Surveys__c ws = new Warranties_and_Surveys__c();
ws.Warranty_Survey_Account__c = '123';
ws.Project_Country__c = 'US';
// Please Add the remaining required fields like above to insert the Warranties_and_Surveys__c records.
Insert ws;
}
static testMethod void testWarrantiesSurveyonUpdate()
{
Warranties_and_Surveys__c ws = new Warranties_and_Surveys__c();
ws.Warranty_Survey_Account__c = '123';
ws.Project_Country__c = 'US';
// Please Add the remaining required fields like above to insert the Warranties_and_Surveys__c records.
Insert ws;
ws.Warranty_Survey_Account__c = '876';
update ws;
}
}
Thanks,
Maharajan.C
'warrantyAmountCalculation.beforeInsert(trigger.new);' line of code in the trigger.
Cheers,
M
Thank you for your help.
M
trigger warrantyValueCalculation on Warranties_and_Surveys__c (before insert, before update) {
if (Trigger.isInsert)
{
for (Warranties_and_Surveys__c warRec: trigger.new)
{
if(warRec.Warranty_Survey_Account__c=='123' || warRec.Warranty_Survey_Account__c=='456' || warRec.Warranty_Survey_Account__c=='789' || warRec.Warranty_Survey_Account__c=='136' || warRec.Warranty_Survey_Account__c=='764' || warRec.Warranty_Survey_Account__c=='111')&&(warRec.Project_Country__c=='US')){
warrantyAmountCalculation.beforeInsert(trigger.new);
}
}
}
else if(Trigger.isUpdate)
{
for (Warranties_and_Surveys__c warRec: trigger.new)
{
if((warRec.Warranty_Survey_Account__c=='001f100001M2FVP' || warRec.Warranty_Survey_Account__c=='876' || warRec.Warranty_Survey_Account__c=='590' || warRec.Warranty_Survey_Account__c=='327' || warRec.Warranty_Survey_Account__c=='970' || warRec.Warranty_Survey_Account__c=='327')&&(warRec.Project_Country__c=='US')){
warrantyAmountCalculation.beforeInsert(trigger.new);
}
}
}
}
Thanks,
Maharajan.C