I'd like to use the metadata API directly to delete a class from a production Org.

In addition to deleting the class my goal is to learn about using the Metadata API. Hence I want to avoid using the Force.com IDE, Eclipse or the Ant Migration tool as they don't reveal the structure of the zip file. Well, I'm not too sure about the Ant Migration tool, but from what I've read you don't give it the zip file, but rather the elements that go into it.

The question How do you delete a class from production without using an IDE? is very similar to this, but I'm specifically after how the zip file should be structured.

Do I just zip up a destructiveChanges.xml file and send the base64 encoded bytes? Maybe to delete a class I need a package.xml and a classes directory that contains a classname-meta.xml file like the following:

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

I've got some .NET code for calling deploy(), but I can't figure out what needs to go into the zip.

// Code that creates an instance of the MetadataService with a valid session.
MetadataService metadataService = ...;

// Get the bytes for the testing zip file from the file system
byte[] zipFile =     System.IO.File.ReadAllBytes(@"C:\path to sample\package\deleteClass.zip");
DeployOptions deployOptions = new DeployOptions() { rollbackOnError=true, singlePackage=true };
AsyncResult ar = metadataService.deploy(zipFile, deployOptions);

// More code that calls checkStatus using the AsyncResult.Id until done

// If the AsyncResult.state isn't Error get the DeployResult with checkDeployStatus()

The Stackoverflow question How do I delete an Apex class in Salesforce Enterprise Edition using Eclipse? is also close to what I need, but isn't dealing explicitly with the contents of the zip file.

1 Answer 1


I've got it working. I needed both the destructiveChanges.xml and the package.xml in the same zip file. Reference - Deleting Files from an Organization.

Zip file contents:

  1. package.xml
  2. destructiveChanges.xml


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

destructiveChanges.xml (Note that I needed to delete the corresponding unit tests in the same deployment):

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

Incidentally, make sure the quotes in the xml files don't get mangled when copying and pasting from the web.

You must log in to answer this question.

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