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
jonpilarski1.3914448382645588E12jonpilarski1.3914448382645588E12 

Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required

Hi,

I have executes test class successfully in sandbox several times. After I do code coverage shows 95%. When I attempt to deploy to production I get error:

Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required

I see many threads on this and have tried many things...At first I put all logic in class and merely called class from trigger. Now I moved all logic into trigger. Still test fine in sandbox but not in production.
Here is trigger and test class.

Thanks,

Jon

@isTest
private class USDTestClass {
       static testMethod void validate() {

   
  
        contact[] contacts = new contact[] {
        new contact(LastName='Sand1',FirstName='Debbie'),
        new contact(LastName='Sand2',FirstName='Carla'),
        new contact(LastName='Sand3',FirstName='Bob'),
        new contact(LastName='Sand4',FirstName='Jon'),
        new contact(LastName='Sand5',FirstName='Bill')
        };
      
        insert contacts;


    USD_Eform__c[] eforms = new USD_Eform__c[] {
        new USD_Eform__c(Contact__c=contacts[0].id,Eform_Type__c='Freshman Questionnaire',name='no name'),
        new USD_Eform__c(Contact__c=contacts[1].id,Eform_Type__c='Freshman Questionnaire',Majr_area_of_interest1__c='xxxEngineering', Majr_area_of_interest2__c='Soccer',Pre_Professional_prog__c='Pre-Med', name='one'),
        new USD_Eform__c(Contact__c=contacts[2].id,Eform_Type__c='Freshman Questionnaire',Majr_area_of_interest1__c='Junk Science',Majr_area_of_interest2__c='abcEngineering',Pre_Professional_prog__c='Pre-Dental', name='two'),
        new USD_Eform__c(Contact__c=contacts[3].id,Eform_Type__c='Freshman Questionnaire',Majr_area_of_interest1__c='Junk Science',Majr_area_of_interest2__c='fff jjjj',Pre_Professional_prog__c='Pre-Health',name='three'),
        new USD_Eform__c(Contact__c=contacts[4].id,Eform_Type__c='Freshman Questionnaire',Majr_area_of_interest1__c='abc Engineering Mechanical',Majr_area_of_interest2__c='aaa Engineering',Pre_Professional_prog__c='Pre-Health', name='four honor')
        };
      
        insert  eforms;
      
         
       List<USD_Eform__c> eFormList = [select id, Eform_Type__c, name,  Majr_area_of_interest1__c, Majr_area_of_interest2__c, Pre_Professional_prog__c,  Assignee__c
                                       from USD_Eform__c];
         

      for(USD_Eform__c e: eFormList) {
    
      if(e.name == 'one'){
         System.assertEquals('Rick Olson', e.Assignee__c);
      }
      if(e.name == 'two'){
         System.assertEquals('Rick Olson', e.Assignee__c);
      }
      if(e.name == 'three'){
         System.assertEquals('Casandra Gomez', e.Assignee__c);
      }
      if(e.name == 'four'){
         System.assertEquals('Jim Gump', e.Assignee__c);
      }        
        
      System.debug('Final>>'+e.Assignee__c);  
      }

      
 


//      System.assertEquals(90, b.Price__c);
    }
}

trigger USD_Eform_BI on USD_Eform__c (before insert) {


// USD_Eform__c[] eform = Trigger.new;


   for (USD_Eform__c e: Trigger.new) {
     //USD_Eform_BI.setAssignee(eform);
   
     Integer honorsResult = 0, areaOfInterestResult1 = 0, areaOfInterestResult2= 0,preHealthResult= 0 ;
     string nameValue ,areaOfInterst1Value,areaOfInterst2Value,preHealthValue ;

if(e.Eform_Type__c.equals('Freshman Questionnaire')) {

   nameValue = e.name.toUpperCase();
   
   try{
      areaOfInterst1Value = e.Majr_area_of_interest1__c.toUpperCase();
   }catch(NullPointerException ne){
 
   }

   try{
      areaOfInterst2Value = e.Majr_area_of_interest2__c.toUpperCase();
   }catch(NullPointerException ne){

   }
   try{
      preHealthValue = e.Pre_Professional_prog__c.toUpperCase();
   }catch(NullPointerException ne){

   }
 
   try{
      honorsResult = nameValue.indexOf('HONOR',0);
   }catch(NullPointerException ne){
      honorsResult = -1;
  }

   try{
      areaOfInterestResult1 = areaOfInterst1Value.indexOf('ENGINEERING');

   }catch(NullPointerException ne){
      areaOfInterestResult1  = -1;
   }
 
   try{
      areaOfInterestResult2 = areaOfInterst2Value.indexOf('ENGINEERING');

   }catch(NullPointerException ne){
      areaOfInterestResult2  = -1;
   }

   try{
      preHealthResult = preHealthValue.indexOf('PRE-HEALTH',0);  
   }catch(NullPointerException ne){
      preHealthResult  = -1;
   }

   if(honorsResult>=0) {
      //Honors
      e.Assignee__c = 'Jim Gump';    
   }else
    if(areaOfInterestResult1 >=0 || areaOfInterestResult2 >=0) {
      //Engineering
      e.Assignee__c = 'Rick Olson';   
   }else
    if(preHealthResult >=0) {
     //Pre-Health
      e.Assignee__c = 'Casandra Gomez';  
   }else {
      e.Assignee__c = null;
   }
 
 
   honorsResult = -1;
   areaOfInterestResult1 = -1;
   areaOfInterestResult2 = -1;
   preHealthResult = -1;

  }


   }   

 
}
GSBassoGSBasso
Dumb question I'm sure but are you deploying your test class along with your trigger?

Otherwise I don't really have any insight as to why Salesforce would report that your trigger has 0% code coverage based on the test class you've posted.

One suggestion I might offer with regards to your test method (and this isn't going to help you with your immediate issue) is that when you populate eFormList I would restrict your query to only the ids of the records you just inserted. In other words, after inserting eforms collect all the resulting ids into a set or list and use this as a filter on your query for popluating eFormList. As it stands now your query will return every USD_Eform__c record in the system, which potentially could be rather large.
jonpilarski1.3914448382645588E12jonpilarski1.3914448382645588E12
Not a dumb question. I am NOT deploying test class. I need to ??? Why?
GSBassoGSBasso
Hi,

Yes - you absolutely need to deploy the test class (i.e. include it in your package).

The test will be run automatically as part of the deployment (indeed, all tests will be run).

This is standard practice when deploying to a production instance (when you deploy to a sandbox you can bypass running any tests).

A production deployment will only be successful if all tests pass (technically all non-packaged tests).
jonpilarski1.3914448382645588E12jonpilarski1.3914448382645588E12
Coolio…was able to deploy with test class. Thanks!!!