Thanks for the help yesterday. I have my trigger written and am now working on my test class.

I am totally confused by the developer console and the testing process. Yesterday, my test results in the Developer Console showed 45% code coverage (in the bottom left portion of the TEST tab). Today, when I looked at my trigger in SF, it showed 72% coverage. I updated my trigger this morning to add new conditions. I've tested the trigger in my Sandbox, by updating each condition on the parent record and achieving the desired result on the child record.

I ran my tests again from the Class page and it passed. Looking at my trigger again (on the Trigger page), it shows 72% coverage. I switched over to Developer Console and tested the Class again. It gives a message of "Success", but shows nothing at all on the Tests tab. When I open the trigger in the Developer Console, it says Code Coverage: None. Yesterday, I could see the red and blue lines on my trigger, today, I get nothing.

I'm getting frustrated, as I have no idea how much coverage my trigger has... let alone if I am even doing this correctly. This "simple" update of one field has turned into 155 lines of code, which I'm sure is due to my crappy apex writing.

Here is my test class:


public class UpdateStatusTest {

    testMethod static void testUpdateStatus(){
    Account a = new Account(Name='Test Account 1', vRad_Company_Type__c = 'Other', OwnerId = '00570000001RigK', Operational_Status__c='Operational', 
    Nighthawk_Service_Rep__c = 'Tier 1', Incumbent_Lookup__c='a067000000k24FL', Practice_Live_Date__c=system.today(), BillingState='MN');
        insert a;
       System.debug('Account a:'+a);

    Master_Contract__c MC = new Master_Contract__c(Practice__c = a.id, Contract_Status__c = 'Draft');  
        insert MC;
        System.debug('Master_Contract__c MC:'+MC);

    Account aU = new Account(id=a.id,Operational_Status__c = 'Lost');
         update aU;   
        System.debug('Account aU:'+aU);

    Account aV = new Account(id=a.id,Operational_Status__c = 'Active');
         update aV;   
        System.debug('Account aV:'+aV);

    Account aW = new Account(id=a.id,Operational_Status__c = 'IT GO');
         update aW;   
        System.debug('Account aW:'+aW);

    Account aX = new Account(id=a.id,Operational_Status__c = 'Cancelled');
         update aX;   
        System.debug('Account aX:'+aX);

  • 4
    Download Eclipse and use a real IDE instead. IMO Salesforce is failing by pushing this online dev console. There are so many tools/features you are missing out on by doing this.
    – dphil
    Dec 2, 2014 at 16:46
  • 2
    If I had a dollar for every time I've said that, I would never need to work again.
    – sfdcfox
    Dec 2, 2014 at 16:49
  • OK. I have Eclipse. I will try it there...
    – Robin L
    Dec 2, 2014 at 17:00
  • Or Download Sublime Text and get Mavens Mate for it. I used to use Eclipse, but now that I've switched over, I'm never going back. And yeah the Dev Console is very inconsistent and buggy when it comes to testing.
    – Minutiae
    Dec 2, 2014 at 19:50
  • I tried installing Maven's Mate once. It was a total cluster...but I hear it is worth it.
    – Robin L
    Dec 2, 2014 at 20:27

1 Answer 1


Regardless of the coverage you have in the Dev Console, there's a couple of very important things missing from your test class. First, I don't see the following anyplace in your code after you've created your test data:


The Test.startTest method marks the point in your test code when your test actually begins. Each test method is allowed to call this method only once. All of the code before this method should be used to initialize variables, populate data structures, and so on, allowing you to set up everything you need in order to run your test. After you call this method, you get a fresh set of governor limits for the remainder of the test OR until you call Test.stopTest. See An Introduction to Apex Code Test Methods for more on this.

Next, and most important, I don't see any system asserts after your trigger will have executed as to what you expect to have happened. Test classes are more than about getting coverage for lines of code. One can nearly always do that, but that doesn't assure you have good code. Your test class should also make certain that the code your testing also does what you expect it to.

You've used system.debug statements in your code at various points to check to see what was happening. Now that you presumably know your code works, it would be a good idea to replace those with system.asserts, especially where you know it's causing your trigger to execute and expect the trigger to perform certain actions on your data. You want to assert the changes after the trigger will have fired.

  • I just tried adding test.startTest; and now my test is failing.
    – Robin L
    Dec 2, 2014 at 20:09
  • I got test.startTest() to work, but I honestly don't understand what this does for my test code. Other than adding a line of code, I'm not seeing any difference in the outcome, at all. I don't see this code in any other test classes that were written by predecessors. Why is this code so critical?
    – Robin L
    Dec 2, 2014 at 20:16
  • 1
    See my edited answer. Its all about governor limits. If you create a lot of test data, (happens in complex orgs & with opportunities, etc) you consume a lot of governor limits before you ever start to test. You get new limits when you run the command. Take a look at your debug log and you'll see it take place.
    – crmprogdev
    Dec 3, 2014 at 0:17

You must log in to answer this question.

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