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
Manish Kumar 23Manish Kumar 23 

Deleting Class in Production getting Code coverage Error

Hi All, 

When I am trying to Deleted Class from Production I am getting error

Average test coverage accross all apex classes and trigger is 58% at least 75% test coverage is required. Please see below snapshot User-added image
Anurag SaxenaAnurag Saxena
Hi Manish,

Below are the steps:
 
1) From Force.com IDE, select the class that you want to delete (Look for .xml extension )
2) Open that .xml version of your class and change the Status tag to Deleted.
3) Right click and save the file.
4) Now select "SRC" folder and right click--->Select  Force.com---> select Deploy to server
5) Log into your production org and follow the steps.
 
Note: if you have any test class for the class that you are deleting make sure you do the same like above and then select those 2 classes for final deployment.
 
Hope it helps.

Please choose as best answer

Thanks:)
Manish Kumar 23Manish Kumar 23
I have performed the same step but not sure why I am geeting error
Anurag SaxenaAnurag Saxena
Hi Manish,

This test class is associated with class while you are trying to delete the test class, salesforce running all tests and the coverage of the class is not fulfilled.

you have to replace the test class or may I know the reason to remove the test class?

So it would be easier to understand?

Thanks:)
 
Manish Kumar 23Manish Kumar 23
Hi Anurag,

We are in a process of cleaning up the unwanted class, trigger in SFDC and because of that I am performing this activity.

 
Anurag SaxenaAnurag Saxena
Did you remove the class or trigger associated with the test class?
Manish Kumar 23Manish Kumar 23
That is what I am trying to do , I am trying to delete trigger /Class using IDE , but getting above error.
Anurag SaxenaAnurag Saxena
Try to delete through workbench ,let me know what happens?
 
Anurag SaxenaAnurag Saxena
Otherwise this will solve the issue

You can leave the trigger/class enabled but comment the entire code in the trigger/class (in sandbox) and deploy it.
Hopefully there would be a test class creating / updating / deleting (depends on action of trigger/class) records in a test class, so that would cover your trigger as 100%.
If not then you just need to write a small test class of 3-4 lines to create a record of the object and that's it.

You have a trigger/class in Production that does nothing and is 100% covered.

Commenting the code also helps, if you ever want to uncomment the code back.

If you deploy the fully commented code trigger and its test class (ie if test class is required), then during deployment, it will pick the version in the changeset.

(Its a workaround, but solves the problem of not required trigger).