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
Bernd NawrathBernd Nawrath 

How to delete an apex class

Hello dear community, I was wondering how exactly to delete an apex class because obviously you can't do that in the production area, I already tried deleting it from my sandbox which worked but it didnt have any impact on my actual production area.
Thanks in advance
Shaijan ThomasShaijan Thomas
1.Comment all code inside the class in Sandbox. 
2. Migrate the class to production.
3. use ANT destruction command for the class.
it will work
Thanks
Shaijan Thomas
KaranrajKaranraj
You can't delete the apex class directly in production but through eclipse you can delete the apex class and trigger. Follow the below steps to do that in production instances,
  • Create new project in eclipse and download all the source code from production
  • Open the meta-data of the file you want to delete in production and change the status to Delete
  • Click save to server to delete the class in the production
<?xml version="1.0" encoding="UTF-8"?>
     <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
         <apiVersion>29.0</apiVersion>
         <status>Deleted</status>
     </ApexClass>
I strogly recommend this method to try first in the dev or sandbox instance and get comfortable and then do the same step in production.

 
goabhigogoabhigo
First, ensure you have backup of the class (Eclipse, BitBucket/GitHub, etc.).

From the Knowledge Article (https://help.salesforce.com/apex/HTViewSolution?id=000006188&language=en_US):
- 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.

Does this help? Let me know if you have trouble in locating the xml part of the file.

--
Abhi
goabhigogoabhigo
Apologies for cross-post @Karan. 
KaranrajKaranraj
@Anhi - You have provided more information than me, I strongly endrose your answer :)
goabhigogoabhigo
Thanks Karan :)

@Bernd, more useful discussions - http://salesforce.stackexchange.com/questions/23229/best-way-to-delete-unused-apex-classes-and-triggers-in-production

There are always multiple solutions in Force.com ;)

--
Abhi
Abhishek Shukla 97Abhishek Shukla 97
Hello All, 

In the developer Edition I tried this : 

1: Open Setup 
2; Pltform Tools>Custom Codes> Apex Classes> Locate the Class
3: Delete 

Although it deleted the class for me but I have seen nobody suggested it yet could you please help me to know is it a recommended step or not??
goabhigogoabhigo
Abhishek, if you read the question and related replies properly, you will know that it was about deleting the class in a production org, not DE.
Tien Le 488Tien Le 488
Thank you, @Abhishek Shukla 97. Your suggestion help my scenario!!