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
Jon SheaJon Shea 

Inherited Apex - Insufficient Coverage


Looking for a little direction to get my org cleaned up. I've inherited a few years worth of unmaintaned Apex and VF pages that are causing all kinds of problems - the most immediate of which is preventing me from deploying change sets. 

I fixed a number of SOQL related errors for one specific change set, but I'm still unable to delpoy. Apparently my code coverage is only 66%. So my question is: Where do I even start looking to address the gap from 66% to 75% ?  

Short term goal is simply to get a change set deployed. I know longer term we'll need a more comprehensive update to existing customizations.

The options I see are: 
  - Get coverage up to 75% percent (unsure where to start here since I'm just getting a general error message - and no specific classes or triggers are called out)
  - Start deleting classes that are no longer relevant (scary because I'm unsure of what other issues this may cause....)

Any help, or general direction on how to start tackling this issue would be great. Thanks!

shashi lad 4shashi lad 4
Ex. If you are deploying 5 classes from sandbox to prod and these classes does not have test classes for them then you can face issue. However, if you include test classes for all 5 classes in changeset than it should work fine as long as you have more than 75% test coverage on those 5 classes. 

As far as prod is concerns, You should clean up those and setup your goal for 85% or higher test code coverage...

Did i address your issue or may be i'm missing something?

Jon SheaJon Shea
Hi Sashi - thanks for your help. 

In my original change set I only had 1 class (the one I want to update). But when I tried to Validate I recevied errors in many other classes. So, I'm confused if validation only looks at the classes in your change set, or all classes in your org ? 

However I will look to make sure that all the other Apex classes I updated have the appropriate test classes. 


 - Jon
buyan thyagarajanbuyan thyagarajan
 Unfortunately if you try validating one class , it is going to complain about dependant classes and each dependant class will lead to a cyclic situation which will go nowhere. If your goal is to increase code coverage, i think you can consider the following options.
1. Look at all apex classes , make a list and see which ones are used in visual force pages , create a dependant list of components like visual force, other apex classes.
2. Then you can remove the unwanted apex classes and do a rewrite of the code.

Now this would involve more time and effort which would be the best approach.
If you are pressed for time , then you can run code coverage for all the classes by running them on dev console and do the following.
a. Create test classes to increase the code coverage for the classes which are between 0 to 40% first.
b. Ensure the rest of apex classes have 80% code coverage by creating code on the test classes.

Let me know your thoughts on this and please click like if you like my answer..
Are you a developer yourself and how familiar are you with salesforce?