6

Creating a class and deploying it from a sandbox environment to the production environment has been simple:

  1. Under "Custom code > Apex classes", create a class and test.
  2. Create a change set in sandbox.
  3. Deploy the change set in production.

If I delete a class in the sandbox environment, it doesn't show up when I go to create a change set, so it's not possible to delete the class from production. I'm a complete beginner to Salesforce and I hear things like "ANT" or "Workbench" for doing this, but I really have no idea how these things work. I'm not looking to do anything complicated, just create a "delete class" change set.

Another post I saw suggested commenting out the entire class and then creating a change set for that, but I tried to do that and I get an error instead:

Error: Compile Error: Unexpected token '<EOF>'. at line 44 column 1

How do I delete a class with a change set?

3 Answers 3

10

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.

5

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).

-1

For anyone who's going to encounter the same problem in the future: I tried @Przemysław's suggestion, which generally follows the official tutorial on this topic , however it did not work in my case.

Setting the Single Package checkbox, produced package.xml not found error. When it was unchecked though, the workbench was crying 'problem: Not in package.xml'. Only when I put exactly the destructiveChanges.xml code into the package xml it started working.

You must log in to answer this question.

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