How to delete Apex class?

As Phil said - it's not possible to delete Apex Classes with Change Sets.

However, I would really recommend you to use Workbench here, it's very straightforward. All you need to do is to create just two files:

package.xml

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <version>47.0</version>
</Package>

destructiveChanges.xml

<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>MyApexClass</members>
        <members>MyAnotherApexClass</members>
        <name>ApexClass</name>
    </types>
    <version>47.0</version>
</Package>

And then compress them to the ZIP archive with a name of package.

Then:

  1. Go to https://workbench.developerforce.com/login.php
  2. Log in using your credentials
  3. Point your mouse to Migration -> Deploy
  4. Choose your ZIP file
  5. Check Rollback On Error and Single Package checkboxes
  6. Click Next.

And if there were no errors due to some dependencies you have your Apex classes deleted.


Change Sets cannot be used to delete components. You have the option to use a destructive changes file in a deployment, as discussed here. To do this you need to ensure that any references to the class to be deleted have already been removed in a previous change set/deployment. This means the deletion is actually a multi-step activity; you can't do everything in one go.

Note that the class's meta XML includes the "status" setting for the class. You can set this to "Deleted" as part of your change set definition and this might do what you want without the need to use a destructive changes file (again, assuming all reference to the class has already been removed in a previous change set).

Tags:

Apex

Lightning