0

I have a code coverage of 100% for my trigger in Sandbox but when 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 the error, despite my code being covered 100% in Sandbox

enter image description here

I do not have any other test class for my code

enter image description here

What am I missing? Thanks

here 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;
}

here is 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;
       
   }
}

2 Answers 2

1

The 74% value is cumulative across all unit tests in your org (not including installed packages). You will need to review your code coverage in production and fix any other classes that are below 75%. This situation usually occurs because of a combination of unit tests that do not use assertions and use try-catch blocks, and changes to production made without going through a standard deployment process.

0

It's OK, I found the solution. I was updating the list directly which was causing the code coverage failure.

I just changed if(cList.size() > 0) update cList; to

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.