+ Start a Discussion
Hermann OuréHermann Ouré 

Code Coverage error on Trigger despite showing 100%

Hello,

I have a code coverage of 100% for my trigger but uploading my packages to production I have an error 
Code Coverage Failure
Your code coverage is 74%. You need at least 75% coverage to complete this deployment.

I really don't understand why when my code is covered 100%

User-added image

my Trigger:
 
trigger CaseConcernAircallDateTrigger on Task (after insert) {
   
    List<Case>  cList = new List<Case>();
    for(Task t: Trigger.New) {
        if(t.WhatId!=Null && t.whatId.getsObjectType() == Case.sObjectType){
            Case c = new Case();
            c.Id = t.whatId;
            c.Last_Aircall_Logged__c = t.CreatedDate;
            cList.add(c);
        }
    }
   
    if(cList.size() > 0) update cList;
}

my Test class:
 
@isTest
public class CaseConcernAircallDateTriggerTest {
    @isTest static void testAircallDateUpdate() {
        
        
        Contact con = new Contact (FirstName = 'First Name',LastName = 'Test');
        insert con;
        
        Case c = new Case(Status = 'New',ContactId = con.Id,Phone_Number__c = '123456789');
        insert c;
        
        Task t = new Task(Subject = 'Test', WhatId = c.Id);
        insert t;
       
        c.Id = t.WhatId;
        c.Last_Aircall_Logged__c = t.CreatedDate;
        update c;
       
    }
}

Thank you
 
Best Answer chosen by Hermann Ouré
AmitSoniAmitSoni
Update your trigger either with insert/upsert like below:
 
if(cList.size() > 0) upsert cList;

 

All Answers

ShirishaShirisha (Salesforce Developers) 
Hi Hermann,

Greetings!

There might be an another test class which is also covering the code for your trigger.So,I would suggest you to check the list of test classes which are covering for the trigger and make sure you add the test classes while deploying the trigger to the production.

You can check the list of the test classes by clicking on the down arrow symbol as shown below:
User-added image

Once,you click on the down arrow then you will get to know which test class covered the trigger with the percentage.So,it will be easy to deploy the trigger code as well.

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
mukesh guptamukesh gupta
Hi Hermann,

i found in your code, you are not insert case but only update dirctly case list. So first you need to insert case.

If this solution is usefull for you, Please mark as a Best Answer to help others.


Regards
Mukesh



 
Hermann OuréHermann Ouré

Hello Shirisha,
Thanks for your reply.

I just checked but it seems that there is only 1 class and it looks covered at 100%
User-added image

Hermann OuréHermann Ouré

Hello Mukesh,
I am a complete Novice,
At what Line should I add insert case?

I have made a few tries without success.
Thanks

AmitSoniAmitSoni
Update your trigger either with insert/upsert like below:
 
if(cList.size() > 0) upsert cList;

 
This was selected as the best answer
mukesh guptamukesh gupta
Hi Hermaan,

Insted of update you need to use   

if(cList.size() > 0) insert cList;

If this solution is usefull for you, Please mark as a Best Answer to help others.


Regards
Mukesh