Is there a way to hard-delete custom objects using the Force.com migration tool? When you deploy a DestructiveChanges payload, the objects are "soft-deleted" and not erased from the platform. This creates an issue when you subsequently try to push back in those objects.

Is there a way to do this?

  • Hmm, the documentation doesn't mention hard deletes. salesforce.com/us/developer/docs/daas/…
    – Mike Chale
    Commented Jun 11, 2013 at 17:00
  • 1
    Yeah, went up and down the documentation about a hundred times. :) Commented Jun 11, 2013 at 17:19
  • Are you sure that's the "push back" that's causing the error? Deleted objects get API_Name_del__c instead of API_Name__c. Maybe you're trying to delete an object while there's one with same name in the bin already?
    – eyescream
    Commented Jun 11, 2013 at 17:53
  • I'm deleting the objects which is then creating the Object_del__c. That's what I mean by a soft delete. I need a full erase of the object so that I can re-deploy it which would include removing the Object_del__c. Commented Jun 11, 2013 at 19:27

4 Answers 4


A hidden gem in the Metadata API deploy operation takes a DeployOptions structure, in it is a purgeOnDelete setting that will do what you need!

purgeOnDelete. If true, the deleted components in the destructiveChanges.xml manifest file aren't stored in the Recycle Bin. Instead, they become immediately eligible for deletion. This field is available in API version 22.0 and later. This option only works in Developer Edition or sandbox organizations; it doesn't work in production organizations.

Extending Salesforce Migration Tool to Support PurgeOnDelete.. For some reason this excellent feature has still not been exposed by the Salesforce Migration Tools via the sf:deploy Ant Task. However with a bit of Java skills you can create a new deploy Ant Task by extending the current one, to expose the attribute to your Ant build scripts, for example...

<taskdef name="deploypurge" classname="com.salesforce.ant.SFDCDeployPurge" classpath="../lib/ant-salesforce.jar"/>
<deploypurge purgeOnDelete="true" username="${sf.username}" password="${sf.password}" serverurl="${sf.server}" deployRoot="stage/deploy" singlePackage="true" runAllTests="false" rollbackOnError="false" allowMissingFiles="true" maxPoll="2000" pollWaitMillis="5000"/>

Prebuilt ant-salesforce.jar with deploypurge in it. You can download a modified ant-salesforce.jar here from the FinancialForce.com Developers Github repo (be warned this is API v22.0, though you can use it to deploy code at any version).

Building your own extended ant-salesforce.jar. If you want rebuild a new version, then you need to download this Java class, compile it, unzip the ant-salesforce.jar (rename .jar to .zip), put it in and zip it back up again and your all set!


This is now exposed in the Force.com migration tool by default. You may now use purgeOnDelete="true" in your build.xml to permanently delete your destructive changes. This only works on developer/sandbox orgs, and does not work on production orgs.


  <sf:deploy purgeOnDelete="true" username="${sf.username}" password="${sf.password}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" deployRoot="mypkg" rollbackOnError="true"/>

None that I know of. Whenever I have needed to do a hard delete, it's been a manual step after destructive changes get deployed.

If there is a workaround for your particular situation, it probably involves changing the name of the object/field you are (re-)deploying, but I couldn't give more specific advice without more info.


Just a thought: could you script something to do this with CURL type requests to the salesforce web UI?

  • 1
    Seems to me like this would be a massively complicated option, have you ever tried something like this?
    – Matt Lacey
    Commented Jun 13, 2013 at 0:09

You must log in to answer this question.

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