Update: this is less applicable if using SFDX scratch orgs.

This script searches and destroys nearly all metadata in an organization. Use cases include ISV package development and testing within Developer Edition and Sandbox environments.


First paste this macrodef into your build.xml

Then the macro may be called by any build target:

<target name="destroy">

It forces an input prompt for the URL and username:

> (https://test.salesforce.com/?un=username@organization...)

How does it work?

First sf:describeMetadata determines the “shape” of the organization. Then, all components are listed in turn from each metadata type. The results are appended in a destructiveChangesPost.xml manifest which is then deployed back over the org.

Does it unlink dependencies?

Yes. Dependencies are cleared in one metadata deployment. It takes advantage of destructive changes POST-deploy, which clears everything in a single transaction. Specifically:

  • Page Layouts are cleared of custom buttons and custom links
  • Sites are cleared of static resources and visualforce pages
  • Profiles are cleared of default application visibilities
  • Roles are cleared of their parent hierarchy association

What cannot be destroyed?

Some metadata types such as Assignment Rules act as permanent containers for the individual rules. Other metadata types such as Record Types do not support the delete operation. These problematic types fall into three categories.

Containers that cannot be destroyed:

  • Assignment Rules
  • AutoResponse Rules
  • Escalation Rules
  • Matching Rules
  • Sharing Rules
  • Workflow Rules

Standard components that cannot be destroyed:

  • Field
  • Object
  • Layout
  • Profile
  • App Menu
  • Matching Rule
  • TopicsForObjects
  • Clean Data Service
  • Business Process as in Case record type
  • Community as in Idea Zone, not to be confused with “Network”

Custom components that shouldn’t be destroyed:

  • Force.com Sites (permanent and cannot be destroyed)
  • Flow (destroy the independent FlowDefinitions instead)
  • Certificate (these cannot be regenerated, leave them intact)
  • ConnectedApp (to avoid interfering with consumer secrets etc)
  • CustomObjectTranslation (these are deleted anyway when object is deleted)
  • InstalledPackage (best uninstalled via UI which nags about extensions etc)
  • RecordType (must be destroyed in UI; it starts an async background process)

Other unsupported metadata types are documented in the Metadata API guide

What about Custom Metadata Types?

This script destroys both the named metadata records as well as the custom definition.

Related Posts

Last modified: 4th August 2019


Hi guys,
Thanks for the script, but when I tried it and it failed with this exception
java.net.MalformedURLException: no protocol: ${loginUrl}/services/Soap/T/43.0

I cannot find the reason. Any help will be appreciated.

    Hi Bill, can you type ant -v to confirm which Ant version is running? Add the following line to the build.properties file: loginUrl=https://test.salesforce.com