{"id":"meta_deploy_deleting_files","title":"Deleting Components from an Organization","content":"<a name=\"meta_deploy_deleting_files\"><!-- --></a><h1 class=\"helpHead1\">Deleting Components from an Organization</h1><div class=\"body conbody\">\n<div class=\"shortdesc\">To delete components, perform a deployment with the <samp class=\"codeph nolang\">deploy()</samp> call by using a destructive changes manifest file that lists the\n        components to remove from your organization. You can perform a deployment that only deletes\n        components, or a deployment that deletes and adds components. In API version 33.0 and later,\n        you can specify components to delete before and after other components are added or updated.\n        In earlier API versions, if deletions and additions are specified for the same deployment,\n        the <samp class=\"codeph nolang\">deploy()</samp> call performs the deletions\n        first.</div>\n\n        <div class=\"section\" id=\"deploy_delete_section\">\n<a name=\"deploy_delete_section\"><!-- --></a><h2 class=\"helpHead2\">Deleting Components in a Deployment</h2>\n\n            \n            <p class=\"p\" id=\"destructo_info\"><a name=\"destructo_info\"><!-- --></a>To delete components, use the same procedure as with deploying\n                components, but also include a delete manifest file that’s named\n                    <span class=\"ph filepath\">destructiveChanges.xml</span> and list the components to delete in\n                this manifest. The format of this manifest is the same as\n                    <span class=\"ph filepath\">package.xml</span> except that wildcards aren’t supported.</p>\n\n            <div class=\"box message info\"><div class=\"inner\"><div class=\"bd\"><div class=\"media\">\n<img class=\"img mtm\" src=\"/docs/resources/img/en-us/264.0?doc_id=images%2Ficon_note.png&folder=api_meta\" alt=\"Note\"><div class=\"mediaBd\">\n<h4 class=\"mbs\">Note</h4>\n<p>You can’t use <span class=\"ph filepath\">destructiveChanges.xml</span> to delete items that are\n                associated with an active Lightning page, such as a custom object, a component on\n                the page, or the page itself. First, you must remove the page's action override by\n                deactivating it in the Lightning App Builder.</p>\n</div>\n</div></div></div></div>\n\n            <p class=\"p\" id=\"desctructo_sample\"><a name=\"desctructo_sample\"><!-- --></a>The following sample\n                    <span class=\"ph filepath\">destructiveChanges.xml</span> file names a single custom object to\n                be deleted:</p>\n\n            <div class=\"codeSection xml\"><pre class=\"codeblock brush:xml\" id=\"destructo_sample_code\"><a name=\"destructo_sample_code\"><!-- --></a><span class=\"tag\">&lt;?xml</span><span class=\"attribute\"> version=</span>\"1.0\"<span class=\"attribute\"> encoding=</span>\"UTF-8\"?&gt;\n<span class=\"tag\">&lt;Package</span><span class=\"attribute\"> xmlns=</span>\"http://soap.sforce.com/2006/04/metadata\"&gt;\n    <span class=\"tag\">&lt;types</span>&gt;\n        <span class=\"tag\">&lt;members</span>&gt;MyCustomObject__c<span class=\"tag\">&lt;/members</span>&gt;\n        <span class=\"tag\">&lt;name</span>&gt;CustomObject<span class=\"tag\">&lt;/name</span>&gt;\n    <span class=\"tag\">&lt;/types</span>&gt;\n<span class=\"tag\">&lt;/Package</span>&gt;</pre></div>\n\n            <p class=\"p\" id=\"destructo_also\"><a name=\"destructo_also\"><!-- --></a>To deploy the destructive changes, you must also have a\n                    <span class=\"ph filepath\">package.xml</span> file that lists no components to deploy,\n                includes the API version, and is in the same directory as\n                    <span class=\"ph filepath\">destructiveChanges.xml</span>:</p>\n\n            <div class=\"codeSection xml\"><pre class=\"codeblock brush:xml\" id=\"destructo_also_code\"><a name=\"destructo_also_code\"><!-- --></a><span class=\"tag\">&lt;?xml</span><span class=\"attribute\"> version=</span>\"1.0\"<span class=\"attribute\"> encoding=</span>\"UTF-8\"?&gt;\n<span class=\"tag\">&lt;Package</span><span class=\"attribute\"> xmlns=</span>\"http://soap.sforce.com/2006/04/metadata\"&gt;\n    <span class=\"tag\">&lt;version</span>&gt;<span class=\"ph\">68.0</span><span class=\"tag\">&lt;/version</span>&gt;\n<span class=\"tag\">&lt;/Package</span>&gt;</pre></div>\n\n            <div class=\"box message info\" id=\"desctructo_note\">\n<a name=\"desctructo_note\"><!-- --></a><div class=\"inner\"><div class=\"bd\"><div class=\"media\">\n<img class=\"img mtm\" src=\"/docs/resources/img/en-us/264.0?doc_id=images%2Ficon_note.png&folder=api_meta\" alt=\"Note\"><div class=\"mediaBd\">\n<h4 class=\"mbs\">Note</h4>\n<p>\n                <ul class=\"ul bulletList\">\n                    <li class=\"li\">To bypass the Recycle Bin, set the <a class=\"xref\" href=\"atlas.en-us.api_meta.meta/api_meta/meta_deploy.htm#meta_deploy\" title=\"Uses file representations of components to create, update, or delete those components in a Salesforce org.\"><span class=\"keyword parmname\">purgeOnDelete</span></a> option to <samp class=\"codeph java\">true</samp>.</li>\n\n                    <li class=\"li\">When you delete a roll-up summary field using Metadata API, the field isn't\n                        saved in the Recycle Bin. The field is purged even if you don’t set the\n                            <samp class=\"codeph nolang\">purgeOnDelete</samp> deployment option to\n                            <samp class=\"codeph nolang\">true</samp>.</li>\n\n                    <li class=\"li\">If you try to delete some components that don’t exist in the organization,\n                        the rest of the deletions are still attempted.</li>\n\n                </ul>\n\n            </p>\n</div>\n</div></div></div>\n</div>\n\n        </div>\n\n        <div class=\"section\" id=\"deploy_delete_add_pre_post_section\">\n<a name=\"deploy_delete_add_pre_post_section\"><!-- --></a><h2 class=\"helpHead2\">Adding and Deleting Components in a\n                Single Deployment</h2>\n<p class=\"p\">You can perform a deployment that specifies components\n                to delete in <span class=\"ph filepath\">destructiveChanges.xml</span> and components to add or\n                update in <span class=\"ph filepath\">package.xml</span>. The process is the same as with\n                performing a delete-only deployment except that <span class=\"ph filepath\">package.xml</span>\n                contains the components to add or update.</p>\n<p class=\"p\">By default, deletions are processed\n                before component additions. In API version 33.0 and later, you can specify\n                components to be deleted before and after component additions. The process is the\n                same as with performing a delete-only deployment except that the name of the\n                deletion manifest file is different.</p>\n<a name=\"manifest_files\"><!-- --></a><ul class=\"ul bulletList\" id=\"manifest_files\">\n                <li class=\"li\">To delete components <em class=\"ph i\">before</em> adding or updating other components, create a\n                    manifest file that’s named <span class=\"ph filepath\">destructiveChangesPre.xml</span> and\n                    include the components to delete.</li>\n\n                <li class=\"li\">To delete components <em class=\"ph i\">after</em> adding or updating other components, create a\n                    manifest file that’s named <span class=\"ph filepath\">destructiveChangesPost.xml</span> and\n                    include the components to delete.</li>\n\n            </ul>\n<p class=\"p\" id=\"delete_use_case\"><a name=\"delete_use_case\"><!-- --></a>The ability to specify when deletions are processed is\n                useful when you’re deleting components with dependencies. For example, if a custom\n                object is referenced in an Apex class, you can’t delete it unless you modify the\n                Apex class first to remove the dependency on the custom object. In this example, you\n                can perform a single deployment that updates the Apex class to clear the dependency\n                and then deletes the custom object by using\n                    <span class=\"ph filepath\">destructiveChangesPost.xml</span>. The following are samples of\n                the <span class=\"ph filepath\">package.xml</span> and\n                    <span class=\"ph filepath\">destructiveChangesPost.xml</span> manifests that would be used in\n                this example.</p>\n<p class=\"p\" id=\"delete_package_sample_intro\"><a name=\"delete_package_sample_intro\"><!-- --></a>Sample\n                    <span class=\"ph filepath\">package.xml</span>, which specifies the class to\n                update:</p>\n<div class=\"codeSection xml\"><pre class=\"codeblock brush:xml\" id=\"delete_package_sample\"><a name=\"delete_package_sample\"><!-- --></a><span class=\"tag\">&lt;?xml</span><span class=\"attribute\"> version=</span>\"1.0\"<span class=\"attribute\"> encoding=</span>\"UTF-8\"?&gt;\n<span class=\"tag\">&lt;Package</span><span class=\"attribute\"> xmlns=</span>\"http://soap.sforce.com/2006/04/metadata\"&gt;\n    <span class=\"tag\">&lt;types</span>&gt;\n        <span class=\"tag\">&lt;members</span>&gt;SampleClass<span class=\"tag\">&lt;/members</span>&gt;\n        <span class=\"tag\">&lt;name</span>&gt;ApexClass<span class=\"tag\">&lt;/name</span>&gt;\n    <span class=\"tag\">&lt;/types</span>&gt;\n    <span class=\"tag\">&lt;version</span>&gt;<span class=\"ph\">68.0</span><span class=\"tag\">&lt;/version</span>&gt;\n<span class=\"tag\">&lt;/Package</span>&gt;</pre></div>\n<p class=\"p\" id=\"delete_post_sample_intro\"><a name=\"delete_post_sample_intro\"><!-- --></a>Sample\n                    <span class=\"ph filepath\">destructiveChangesPost.xml</span>, which specifies the custom\n                object to delete after the class\n                update:</p>\n<div class=\"codeSection xml\"><pre class=\"codeblock brush:xml\" id=\"delete_post_sample\"><a name=\"delete_post_sample\"><!-- --></a><span class=\"tag\">&lt;?xml</span><span class=\"attribute\"> version=</span>\"1.0\"<span class=\"attribute\"> encoding=</span>\"UTF-8\"?&gt;\n<span class=\"tag\">&lt;Package</span><span class=\"attribute\"> xmlns=</span>\"http://soap.sforce.com/2006/04/metadata\"&gt;\n    <span class=\"tag\">&lt;types</span>&gt;\n        <span class=\"tag\">&lt;members</span>&gt;MyCustomObject__c<span class=\"tag\">&lt;/members</span>&gt;\n        <span class=\"tag\">&lt;name</span>&gt;CustomObject<span class=\"tag\">&lt;/name</span>&gt;\n    <span class=\"tag\">&lt;/types</span>&gt;\n<span class=\"tag\">&lt;/Package</span>&gt;</pre></div>\n<p class=\"p\">Post destructive changes are processed before running\n                any tests.</p>\n<p class=\"p\">When deleting Apex classes or triggers, Salesforce recommends that\n                as part of the deployment,  you run all local tests from the namespace in order to\n                detect any remaining references to the deleted class or trigger.</p>\n<div class=\"box message info\" id=\"delete_note_version_used\">\n<a name=\"delete_note_version_used\"><!-- --></a><div class=\"inner\"><div class=\"bd\"><div class=\"media\">\n<img class=\"img mtm\" src=\"/docs/resources/img/en-us/264.0?doc_id=images%2Ficon_note.png&folder=api_meta\" alt=\"Note\"><div class=\"mediaBd\">\n<h4 class=\"mbs\">Note</h4>\n<p>The API version that the deployment uses is the API\n                version that’s specified in <span class=\"ph filepath\">package.xml</span>.</p>\n</div>\n</div></div></div>\n</div>\n</div>\n\n    </div><div id=\"sfdc:seealso\" class=\"related-links\">\n<div class=\"pagination pagination-centered\"><ul class=\"pagination\">\n<li class=\"next_page\"><a class=\"link\" href=\"atlas.en-us.api_meta.meta/api_meta/meta_checkdeploystatus.htm\" title=\"checkDeployStatus()\">Next →</a></li>\n</ul></div>\n</div>"}