2

I've moved a lot of my trigger code over into class methods so I can control what order the logic happens in. Each object has one Trigger like this, and each Trigger may might call up to a dozen different classes, and might call the same class method at different points depending on the context.

Below is a demonstration of how I've structured it :

Trigger ContactTrigger(...)
if(Trigger.isInsert){ 
    ContactController.notifyUser(Trigger.new);

    ContactController.assignPhoneNumber(Trigger.new);
    AccountController.AssignToOrg(Trigger.new); }

if(Trigger.isDelete){
    ContactController.notifyUser(Trigger.old);

    ContactController.notifyContact(Trigger.old);

The ContactController would be just a heap of different methods relevant to the Contact object.

Anyway, I've written plenty of Test Methods which focus on one particular class function, or one particular context (i.e. one test for inserting, one for updating, one for deleting). COLLECTIVELY, they cover the class entirely, but the coverage amount displayed only reflects the test method that offers the least coverage. For example, the system focuses on a Unit test that covers 12% of the code (one method) rather than one that covers 90%.

I'm not really sure what to do here. I need to get adequate coverage on classes, but I also need to keep my unit tests specialised to avoid hitting governor limits. Perhaps I need to rethink my code structure?

Thanks in advance for any guidance,

Lachlan.

  • 1
    In the developer console, you can specify which "Test Class Coverage" you are viewing with a drop down in the top left corner, make sure "All Tests" is selected there? If you are referring to the code coverage table in the bottom of the developer console, I might suggest it is returning incorrect results (as has been noted once or twice). Try clearing all test coverage, re-running all tests and opening and closing a few windows a couple of times... – Simon Lawrence Sep 30 '14 at 8:32
  • Cool, its working now :) So I was in the developer console and did have "All Tests" selected, but I found that re-running all tests and reloading the console got the coverage up to 100%. Thanks Simon! – Lachlan B Oct 1 '14 at 1:26
1

Ok, it turns out there was nothing wrong with my code. I just needed to re-run ALL test classes and re-load the developer console page, and the coverage jumped up to 100%. Thanks to Simon Laurence for his prompt response!

  • 1
    Cool. Glad I could be of assistance :) – Simon Lawrence Oct 1 '14 at 8:45
  • 1
    Once the time delay has lapsed, swing back here and mark your answer as the right one so future people/the system knows this was another successful resolution to a problem! – Simon Lawrence Oct 1 '14 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.