Find your content:

Search form

You are here

Contents of the metadata deploy zip file to delete a class in a production org

 
Share

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">
    <apiVersion>20.0</apiVersion>
    <status>Deleted</status>
</ApexClass>

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.


Attribution to: Daniel Ballinger

Possible Suggestion/Solution #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

package.xml:

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

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">
    <types>
        <members>classname</members>
        <members>classname_TestCases</members>
        <name>ApexClass</name>
    </types>
    <version>23.0</version>
</Package>

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


Attribution to: Daniel Ballinger
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/3743

My Block Status

My Block Content