function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SIB AdminSIB Admin 

Code coverage less than 75%.How to exclude classes

Hi,
I am new to Salesforce testing.When I try to push a trigger class it says your code coverage is below 75%.I need to deploy it urgently.I tried running all tests and by going to developer console to check code coverage for each class.
Here is the screenshot
User-added image

I am thinking if I could exclude the classes with miminal coverage from the code coverage so that they do not lower the overall code coverage.I tried that by annotating each class by @isTest but even after that when I tried run all tests and went to develop console I could still see those classes with 0% coverage.
SIB AdminSIB Admin
Here is one of the class that I annotated


@isTest
public class CustomASR_CC extends CustomASR_New{

    public List<Vendor_Service_Agreement__c> contracts {get; set;}
    public List<Affected_Vendor_Account__c> vendorAccounts {get; set;}
    public Decimal totalAnnualSavings {get; set;}
    public Integer ccColspan {get; set;}

    public CustomASR_CC() {

        vendorAccounts = [SELECT Id, Name, Pre_SIB_Contract__c, Post_SIB_Contract__c
                          FROM Affected_Vendor_Account__c
                          WHERE Audit__c = :asr.Audit__c];

        if(asr.Audit__r.Audit_Type__c == 'Waste - Solid, Recycling, & Compost'){
            ccColspan = 10;
        } else if(asr.Audit__r.Audit_Type__c == 'Telecom - Phone, Internet, & Television' || asr.Audit__r.Audit_Type__c == 'Telecom - Television'){
            ccColspan = 10;
        } else if(asr.Audit__r.Audit_Type__c == 'Waste - Medical'){
            ccColspan = 10;
        } else if(asr.Audit__r.Audit_Type__c == 'Armored Car Service'){
            ccColspan = 9;
        } else{
            ccColspan = 9;
        }
    }

    public List<CCExternal_Group> getCCExternal(){

        List<CCExternal_Group> contractGroups = new List<CCExternal_Group>();

        contracts = [SELECT Id, RecordType.Name, Vendor__r.Name, Effective_Date_of_Agreement__c, Initial_Term_Length__c, Renewal_Term_Length__c, 
                            Current_Term_Expiration__c, Fuel_Environmental_Surcharges__c, Price_Increase_Controls__c, Contract_Type__c, Closure_Sale_or_Expiration_Penalty__c, X30_Day_Termination__c, Underlying_Servicer__c,
                            (SELECT Id, RecordType.Name, Vendor__r.Name, Effective_Date_of_Agreement__c, Initial_Term_Length__c, Renewal_Term_Length__c, 
                                    Current_Term_Expiration__c, Fuel_Environmental_Surcharges__c, Price_Increase_Controls__c, Contract_Type__c, Underlying_Servicer__c
                             FROM Vendor_Service_Agreements__r)
                     FROM Vendor_Service_Agreement__c
                     WHERE Audit__c = :asr.Audit__c AND RecordType.Name = 'Post-SIB'];

        for(Vendor_Service_Agreement__c newContract : contracts){
            CCExternal_Group ccGroup = new CCExternal_Group(newContract, this.auditedLocations);
            contractGroups.add(ccGroup);
        }

        //Total Annual Savings
        totalAnnualSavings = 0.00;
        for(CCExternal_Group g : contractGroups){
            totalAnnualSavings = totalAnnualSavings + g.newContract.getAnnualSavings();
        }

        List<CCExternal_Group> filteredGroups = new List<CCExternal_Group>();
        for(CCExternal_Group g : contractGroups){
            if(g.newContract.getAnnualSavings()>0){
                filteredGroups.add(g);
            }
        }

        filteredGroups.sort();

        return filteredGroups;

    }
Wilfredo Morillo 20Wilfredo Morillo 20
You need to create a test class for your trigger that covers at least 75% of the code. The code that needs to meet the requirements is the code that you are trying to deploy and salesforce make sure that the code doesn't brake any existing code in production. 
SIB AdminSIB Admin
Thanks for replying back. Also, I wonder how the trigger got pushed in the past.Today I just added one line to the code and tried pushing it upon which it started giving the error. Has this been added recently? Is there any way to get rid of the code coverage for that particular trigger? I need to deploy it urgently.
saikrishna cheetysaikrishna cheety
Your test class should have atleast 75% code coverage to deploy the code into production
SIB AdminSIB Admin
User-added image
SIB AdminSIB Admin
The above comment shows the exact error I am getting.I was able to deploy another class but getting error when I try to deploy this trigger.
SIB AdminSIB Admin
There is already a test class for ASRInitialization trigger.Not sure why it says 0% code coverage.

@isTest
private class ASRInitializationTest {

    //Create test data
    @testSetup static void setupTestData(){
        //Test Audit
        testData.createTestAudit();
        Location_Audits__c testAudit = [SELECT Id, Name, Audit_Type__c FROM Location_Audits__c WHERE Account__r.Name = 'Test Account'];

        //Test Audit Definition
        Audit_Definition__c testDefinition = new Audit_Definition__c(
            Audit_Type__c = testAudit.Audit_Type__c
        );
        insert testDefinition;
        testDefinition = [SELECT Id, Name, Audit_Type__c FROM Audit_Definition__c WHERE Audit_Type__c = :testAudit.Audit_Type__c];

        //Test ASR Attribute
        ASR_Attribute__c attr = new ASR_Attribute__c(
            Audit_Definition__c = testDefinition.Id,
            Section__c = 'Location Information',
            Section_Label__c = 'My Section Label',
            Object_Type__c = 'My_Object__c',
            Field__c = 'My_Field__c',
            Label__c = 'My_Label__c',
            Hidden__c = false,
            Order__c = 1
        );
        insert attr;
    }
    
    @isTest static void testASRCreate() {
        //Create a new ASR and relate it to the test audit
        Location_Audits__c testAudit = [SELECT Id, Name, Audit_Type__c FROM Location_Audits__c WHERE Account__r.Name = 'Test Account'];
        ASR__c testASR = new ASR__c(
            Audit__c = testAudit.Id,
            ASR_Date__c = System.today()
        );
        insert testASR;
    }


    
    
}