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
JAW99JAW99 

Deployment of test classes to increase code coverage failing

Can someone assist? I must be missing something.

I have 2 triggers in production and sandbox (same in both):

They have 0% coverage in production, 100% and 90+% coverage in sandbox - b/c I have the test classes in the sandbox only. 

I want to deploy these test classed to production. I cannot.

 

The Deploy Error is "Average test coverage across all Apex Classes and Triggers is 69%, at least 75% test coverage is required.

 

This low coverage is what I am trying to fix by deploying test coverage. How can I increase coverage? 

Thanks. 

Andy BoettcherAndy Boettcher

Typically that means you have other test coverage issues in your org (errors or something else).  Run the "Run All Tests" in Setup / Develop / Apex Classes and look for errors.

 

Fix those in Sandbox - then push all of your changes up at the same time.

 

-Andy

JAW99JAW99

I initially tried just deploying one of the test classes and the error I got referenced an uncovered trigger.

So I added the test class relevant to that trigger.

I did not see a reference to an uncovered class.

However now I added a sandbox test class for the last trigger class and receive the same message.

 

I am trying to up my coverage. The error message is not helpful.

Andy BoettcherAndy Boettcher

Yeah - it's not helpful at all.  =)

 

Like I said - odds are you have an error in a Test Class currently in Production.  Run the "Run All Tests" button in Production and see if you get any failures.  If you do - fix them in Sandbox and deploy those + your new ones in one batch.

 

-Andy

JAW99JAW99

OK, so i need to fix all code coverage to make any changes whatsoever? that is what it apepars like.

Andy BoettcherAndy Boettcher

Yeah - you can't deploy with any errors present.  Fix them in the Sandbox first - then you'll be set.

 

I've had this happen before - but usually it's because I didn't stage my data properly in the Test Class or had a new Validation Rule get implemented that broke one.  It's part of the development / testing / deployment cycle.  =)

JAW99JAW99

Thanks. 
The error message isn't clear about what conditions need to be resolved. Also, I wonder how I got 2 apex classes / VF pages deployed in production in the past without 0% coverage. 

Andy BoettcherAndy Boettcher

If you run the "All Tests" button in production (Setup / Develop / Apex Classes) - in the output of that you'll find a "Failed Tests" section.  If you want (and are OK with doing so) - post up the failure stuff here and we can help you parse it.

 

-Andy

JAW99JAW99

Thanks.

I have two similar classes that allow users to add multiple related objects to one custom object. 

 

 

 

public class NotesEntry {

    public List<Task> ords {get; set;}
    private final Ecommerce_Visit__c parOrd;
    public NotesEntry(ApexPages.StandardController myController) {
        parOrd=(Ecommerce_Visit__c)myController.getrecord();
        ords = new List<Task>();
        Task LitOrd = new Task();
        LitOrd.Whatid= parOrd.id;
        LitOrd.Status='completed';
      
               
        ords.add(LitOrd);}

    public void addrow() {
        Task LitOrd = new Task();
        LitOrd.whatid = parOrd.id;
        ords.add(LitOrd);}
            
    public void removerow(){
        Integer i = ords.size();
        ords.remove(i-1);}
            
    public PageReference save() {
        insert ords;
        //PageReference home = new PageReference('/home/home.jsp');
        //home.setRedirect(true);
        //return home; }}
        PageReference parrec = new PageReference('/'+parOrd.id);
        parrec.setRedirect(true);
        return parrec; }}

 

 

and here is the other one. i have been able to build tests for my triggers but tests for these pages has eluded me.

 

public class PMEntry {

    public List<PM_Visit__C> ords {get; set;}
    private final Ecommerce_Visit__c parOrd;
    public PMEntry(ApexPages.StandardController myController) {
        parOrd=(Ecommerce_Visit__c)myController.getrecord();
        ords = new List<PM_Visit__c>();
        PM_Visit__c LitOrd = new PM_Visit__c();
        LitOrd.Ecommerce_Visit__c = parOrd.id;
        ords.add(LitOrd);}

    public void addrow() {
        PM_Visit__c LitOrd = new PM_Visit__c();
        LitOrd.Ecommerce_Visit__c = parOrd.id;
        ords.add(LitOrd);}
            
    public void removerow(){
        Integer i = ords.size();
        ords.remove(i-1);}
            
   public PageReference save() {
        insert ords;
        //PageReference home = new PageReference('/home/home.jsp');
        //home.setRedirect(true);
        //return home; }}
        PageReference parrec = new PageReference('/'+parOrd.id);
        parrec.setRedirect(true);
        return parrec; }}

 

 

 

i would guess the tests would be similar, no? thanks for any help!