Spring'15 - Delete Components before and after Component Updates in a deployment
|Knowledge Article Number||000206765|
Delete Components before and after Component Updates
You can control when components are deleted in a deployment. Use a manifest to specify component deletions before updates, and use another manifest to specify component deletions after updates. Specifying the processing order of deletions relative to component updates provides you with greater flexibility and enables you to delete components with dependencies.
To delete components, use the same procedure as with deploying components, but also include the appropriate delete manifest files. The format of the delete manifest is the same as package.xml except that wildcards aren’t supported.
This feature applies to the Metadata API deploy() call or Metadata API-based tools, such as the Force.com Migration Tool.
The ability to specify when deletions are processed is useful when you’re deleting components with dependencies. For example, if a custom object is referenced in an Apex class, you can’t delete it unless you modify the Apex class first to remove the dependency on the custom object. In this example, you can perform a single deployment that updates the Apex class to clear the dependency and then deletes the custom object by using destructiveChangesPost.xml. The following are samples of thepackage.xml and destructiveChangesPost.xml manifests that would be used in this example.
Sample package.xml, which specifies the class to update:
<?xml version="1.0" encoding="UTF-8"?> <Package xmlns="http://soap.sforce.com/2006/04/metadata"> <types> <members>SampleClass</members> <name>ApexClass</name> </types> <version>33.0</version> </Package>
Sample destructiveChangesPost.xml, which specifies the custom object to delete after the class update:
<?xml version="1.0" encoding="UTF-8"?> <Package xmlns="http://soap.sforce.com/2006/04/metadata"> <types> <members>MyCustomObject__c</members> <name>CustomObject</name> </types> </Package>