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
Prentiss Jones 3Prentiss Jones 3 

Trying to Delete a Apex Class

Need help, I'm in the Force.com IDE. I have deleted the calss in the sandbox, but will not delete in production. 

Class Names: CloneListTest 

Error 1:  test coverage across all Apex Classes and Triggers is 72%, at least 75% test coverage is required.    Tremor Video Production        line 1    Force.com code coverage warning

Error 2:  System.NullPointerException: Attempt to de-reference a null object    CloneListTest.cls    /Tremor Video Production/src/classes    line 56    Force.com run test failure
Best Answer chosen by Prentiss Jones 3
ManojjenaManojjena
Hi Prentiss,

Do one thing modify the test class with like only blank method like below .
 
@isTest
public class CloneListUtil{
  static testMethod void testCloneListControllerOne(){
  
  }
}

And deploy the code to controller and then delete ,
Do you want to delete only the test class or CLoneListController as well .
 

All Answers

Mohit Bansal6Mohit Bansal6

Hi Prentiss

Check this below article.Hope it helps you.
https://help.salesforce.com/apex/HTViewSolution?id=000006188

How to Disable or Delete an Apex Class or Trigger from a Production Org
Knowledge Article Number: 000006188 


Description- An Apex class or trigger must be removed from a production instance if it is blocking a deployment or is no longer needed.
- Apex code may not be modified directly within a Production org, so it requires a couple of steps using Developer tools.
- This article gives instructions using the Force.com IDE
- This is the only way an Administrator or Developer can disable or remove Apex in a Production org.


Resolution- Force.com IDE should be installed and working.
- Connect to the Sandbox Instance using the IDE and find the class or trigger that you want to delete.
- Open the matching .xml file change the Status XML tag from "Active" to "Deleted" if you want to remove the trigger or class, or to "Inactive" if you want to disable the trigger.
- Apex class Status can only be changed to "Active" or "Deleted", not "Inactive".
- Save the file.
- Select the two files (Code and XML) using Ctrl-click, then right click on one of them. Select Force.com > Deploy to server.
- Provide your credentials for the production org and follow the steps.

Regards​

Mohit Bansal

In case, you face any issue, drop me message on forum or Skype me @mohit_bansal17, if you need any help.


Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help

 

Prentiss Jones 3Prentiss Jones 3
Thanks, I have done this. The Class will not delete because of the the erros.

​Error 1:  test coverage across all Apex Classes and Triggers is 72%, at least 75% test coverage is required.    Tremor Video Production        line 1    Force.com code coverage warning

Error 2:  System.NullPointerException: Attempt to de-reference a null object    CloneListTest.cls    /Tremor Video Production/src/classes    line 56    Force.com run test failure
ManojjenaManojjena
Hi Prentiss ,

If you want to delete Apex class from production .You need to pull the apex classes to eclipse . Select the metadata XML fiel related to the class .
You will get the file like below .
 
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>27.0</apiVersion>
    <!--<status>Active</status> --> Relace this line with below line or chnage Active to Deleted 
    <status>Deleted</status>
</ApexClass>
After this save the class it will automatically delete the class from production .

Thanks
Manoj
 
ManojjenaManojjena
Hi Prentiss ,

You only need to pull the apex classes from production and needs to save .
Mohit Bansal6Mohit Bansal6

Hi Prentiss

Just copy and paste code in Sandbox and then in IDE change status to Deleted from Active.

It will delete the class from production.

Regards
Mohit Bansal

Prentiss Jones 3Prentiss Jones 3
Yes That what I'm doing.....

<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>20.0</apiVersion>
    <status>Deleted</status>
</ApexClass>
Prentiss Jones 3Prentiss Jones 3
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>20.0</apiVersion>
    <status>Deleted</status>
</ApexClass>
It's given this as errors
Error 1:  test coverage across all Apex Classes and Triggers is 72%, at least 75% test coverage is required.    Tremor Video Production        line 1    Force.com code coverage warning

Error 2:  System.NullPointerException: Attempt to de-reference a null object    CloneListTest.cls    /Tremor Video Production/src/classes    line 56    Force.com run test failure
ManojjenaManojjena

Hi Prentiss ,

Try to create a object with production credential and pull from production follow the same step in production and let me know if you will get error .

I have deleted 27 classes from one organisation today .
 
Prentiss Jones 3Prentiss Jones 3
Just wonder how to reference the new object?
 
for(ChildRelationship cr : controller.childRecords) {
            if(cr.getRecordAmount() > 0) {
                cr.setSelected(true);
            }
        }

This is Line 56 which is my issue
ManojjenaManojjena
Hi Prentiss ,

What exctly your issue i s,You need to delete the class or you need any solution for your  class or Trigger ? 

 
Prentiss Jones 3Prentiss Jones 3
Need to Delete the class...
Prentiss Jones 3Prentiss Jones 3
User-added image
ManojjenaManojjena
Hi Prentiss ,

Have you created a project in Eclipse with production credential ?
Have you modified the className.cls-meta.xml ?
After modifyed the xml file ,Have you saved the class.

Still you are facing issue ,please send your code to my email ,

manojjena20@gmail.com

 
Prentiss Jones 3Prentiss Jones 3
Thanks for your help I just sent an email
ManojjenaManojjena
Hi Prentiss,

Do one thing modify the test class with like only blank method like below .
 
@isTest
public class CloneListUtil{
  static testMethod void testCloneListControllerOne(){
  
  }
}

And deploy the code to controller and then delete ,
Do you want to delete only the test class or CLoneListController as well .
 
This was selected as the best answer
Prentiss Jones 3Prentiss Jones 3
The CLoneListController as well....I'm trying it out now! 

Thanks....Let you know.
Prentiss Jones 3Prentiss Jones 3
Thanks it Worked!