1

Completed my first Apex Class extension for a visual force page. It works great in the sandbox. Unfortunately I get a code coverage failure when trying to upload to production.

Questions...

  1. Does the code coverage failure have to do with the entire org or just the Change Set Components?
  2. If it is just the Change Set Components how to I get code coverage for my new Apex Class?

I've been going through documentation but haven't found what I needed. I'd appreciate if anyone can narrow my search.

Here is my Apex Class code

public with sharing class SaveExtension
{
    ApexPages.StandardController sc;
    public AVTRRT__Job__c objBJob {get; set;}

    public SaveExtension(ApexPages.StandardController sc)
    {
        this.sc = sc;
        objBJob = [
            select Job_Name__c, Job_Type__c, Ops_Notes__c, Recruiter_notes__c, Submission_notes__c, AVTRRT__Stage__c
            from AVTRRT__Job__c
            where Id in ( Select AVTRRT__Job__c from AVTRRT__Job_Applicant__c where Id = :sc.getId())];

    }

    public ApexPages.PageReference SaveBoth()
    {
        update objBJob;
        return sc.Save();
    }
}

Here is the VF page

<apex:page StandardController="AVTRRT__Job_Applicant__c" extensions="SaveExtension">
  <apex:form >
  <apex:pageblock mode="edit">
       <apex:inputField value="{!AVTRRT__Job_Applicant__c.AVTRRT__Stage__c}" />
       <apex:inputField value="{!objBJob.Job_Type__c}" />
       <apex:CommandButton action="{!saveboth}" value="Save"/>
  </apex:pageblock>
</apex:form> 
</apex:page>

Thanks!

Ed L

2 Answers 2

3

Does the code coverage failure have to do with the entire org or just the Change Set Components? If it is just the Change Set Components how to I get code coverage for my new Apex Class?

Every time you deploy to PROD, the deployment (including via Changesets) will rerun all of the testmethods in PROD - including everything new being deployed.

  1. Did you write a testmethod/testclass for your new class? If not, write it and include it in the changeset. You didn't include that in OP so that could be the easy fix.
  2. If you did write a testclass and it covers your code, then there must be something else in PROD that is not covering enough code in other classes. This then gets more involved to diagnose. Go to PROD and do a run all tests from the Developer Console. Inspect the code coverage. Consider using a fullcopy sandbox to mirror PROD where you can do more complete tests and get logs
3
  • Minor points: Each class gets its own logs. This can sometimes help. Also, consider any new validation rules or workflow rules created or updated since the last deployment. They are usually the cause. It helps to periodically run all tests so you don't get caught off guard when you need to deploy. Where I work, we wrote a daily scheduler that runs all tests and emails the results back to the team so we can fix problems before they halt a deployment.
    – sfdcfox
    Commented Nov 25, 2014 at 6:26
  • ah ... right, run all tests from DC does in fact create separate log file per test class. I was thinking about when I used to deploy from sandbox to PROD via Eclipse IDE and if the deploy failed, the logs for all testclasses were in one log and for me, always > 2MB; I fixed the answer. thanks as always sfdcfox for keeping me accurate
    – cropredy
    Commented Nov 26, 2014 at 22:54
  • 1
    The regular test runs are one of the best things you can do for yourself. There is nothing worse than not having run them for 6 months, having made myriad declarative changes, then one day go to deploy a new changeset and realize that one (or more) of the changes you made over the 6 mo period broke something and caused code coverage to come crashing down. Good luck troubleshooting for the next two weeks. I highly recommend building an automated test solution which tests daily. I built one that's caught a couple of issues overnight, so there was little-to-no guesswork on what to rollback. Commented Nov 27, 2014 at 4:12
0

First deployment under my belt. Thanks to all for the help and input!

Much of my issues stemmed from my prod and sandbox not being in sync. While this was our first deployment we have used the sandbox for experimentation and have allowed it to get out of date. A good lesson learned early on that is easy to fix going forward.

Onward!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .