When trying to delete a class together with its test class, I will receive a code coverage error (0% out of 75%) for both classes, the normal as well as the test class. How to reproduce:

  1. Assume I have:
  • NiceCustomClass.cls
  • NiceCustomClass.cls-meta.xml
  • NiceCustomClasstest.cls
  • NiceCustomClasstest.cls-meta.xml
  1. Then I will go ahead and follow e.g. https://help.salesforce.com/articleView?id=000328218&mode=1&type=1 using a git/jenkins/ant combination, doing following:

  2. Setting the tag in both -meta.xml from "active" to "deleted". Save it, push both -meta.xml file changes and get it validated.

  3. Falidation unfortunately throws as mentioned above:

Code coverage issue, class: NiceCustomClass -- Test coverage of selected Apex Class is 0%, at least 75% test coverage is required

Code coverage issue, class: NiceCustomClassTest -- Test coverage of selected Apex Class is 0%, at least 75% test coverage is required

Is there any sequence we need to follow when deleting the class and test class combination? I would not assume because if first normal class is deleted, test class will fail as it will not find methods used in test class.

Other way round it would fail because of course there would be a 0% test coverage of course.

Also I wonder why it tries to cover code for test class itself as well.

EDIT ADD: I run the validation of those changes against a Sandbox first.

  • If you run a destructive change set including both, it should work. No tests will be run.
    – Adrian Larson
    Jul 12, 2021 at 13:46
  • I just added to above text, that I tried this approach on a Sandbox. Regarding your idea, I also followed the approaches described e.g. on salesforceben.com/way-to-delete-apex-classes-from-production Since it is deletion, it will - at least on production - always run all test classes, even tho I select related/none or whatever.
    – Cmd_Keen
    Jul 12, 2021 at 14:08
  • Not true, destructive change sets do not cause test runs in any environment (so you have to be very careful with them).
    – Adrian Larson
    Jul 12, 2021 at 14:11
  • Ok, then either (unofficial) documentations are incomplete, or me and others (salesforce.stackexchange.com/questions/236700/…) doing things wrong. Are there some specialities we need to keep in mind or some settings in the respective org we need to set or some command line approach? Speaking of cmd, I used to use force-dev-tool (which is deprectaed now I guess?), and when specifying test classes for prod deletion via command, it didn't allow it, as "all test methods need to run". So I am kinda clueless atm :/
    – Cmd_Keen
    Jul 12, 2021 at 14:20
  • Just to be clear, have you tried it as an actual destructiveChanges.xml?
    – Adrian Larson
    Jul 12, 2021 at 15:51

1 Answer 1


You can specify existing unrelated tests to run on classes that are unrelated to your deletion package. If the tests generate 75% coverage for those unrelated classes, then your deployment will succeed. This works with the ant command-line tool and the Developer Workbench.

You must log in to answer this question.

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