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
John NeilanJohn Neilan 

Exclude Class From Code Coverage

Hello,

I wrote a Class to use in my test Classes.  The purpose of this class is to create varius records that I can reference in test classes.  However, when I try to deploy it to production, it shows as 0% coverage and will not let me deploy.  Is there a way I can exclude this class from the code coverage calculation?

Class:
public class TestCreateRecords {

// create and insert a new Account record.
    public static Account createAcct(Integer i){
        Profile ProSys = [SELECT Id
                          FROM Profile
                          WHERE Name='Client Services (Admin)'];
        User U1 = new User(Alias = 'User1',Country='United States',Email='User1@testing.com',EmailEncodingKey='ISO-8859-1', LastName='User1', 
                            LanguageLocaleKey='en_US',LocaleSidKey='en_US',ProfileId = ProSys.Id,TimeZoneSidKey='America/New_York', UserName='User1@testing.com');
        insert U1;

      Account acct = new Account();
        acct.Name = 'Test';
        acct.Region__c = 'USA';
        acct.BillingCountry = 'USA';
        acct.Industry = 'Consumer Goods';
        acct.Status__c = 'Customer';
        acct.Website = 'www.test.com';
        acct.OwnerId = U1.Id;
            
      return acct;
    }
}

 
Best Answer chosen by John Neilan
Balaji Chowdary GarapatiBalaji Chowdary Garapati
John,

  Since you were referring this class only in test classes, you can annotate this class too as test class which will exclude this class from regular apex code and still will be working as it was intended to do so.,

as:

@isTest
public class TestCreateRecords {
//your code

}

Hope it helps.,

Thanks,
Balaji

All Answers

Balaji Chowdary GarapatiBalaji Chowdary Garapati
John,

  Since you were referring this class only in test classes, you can annotate this class too as test class which will exclude this class from regular apex code and still will be working as it was intended to do so.,

as:

@isTest
public class TestCreateRecords {
//your code

}

Hope it helps.,

Thanks,
Balaji
This was selected as the best answer
John NeilanJohn Neilan
Thanks Balaji!  I thought I could do that but wasn't sure.  That did the trick!