4

We are currently migrating our Salesforce development workflows to sfdx. We have got CI up and running with CircleCI and really smooth deployments going for when there are additions to metadata or changes to Apex which is great, however the missing piece for us is how we deploy destructive metadata "changes" (renames, deletes, etc.) I am familiar with the Metadata API and functions like renameMetadata() and deploying descructive changes via a destructivechanges.xml package setup however there doesn't seem to be an easy way to deploy metadata "migrations" using this pattern in sfdx.

Anyone solved this problem or have a workflow in sfdx for this? I've searched high and low in the documentation / online – sorry if I have missed anything! Thinking we might need to build a migration style workflow ala Rails.

2

Destructive XML is completely supported in salesforce dx. All you need is a directory where you will place a package.xml file and a destructiveChanges.xml file.

destructiveChanges.xml will be an XML with all the components you want to delete. Check the documentation here

where destructive is a folder with package.xml and destructiveChanges.xml

 sfdx force:mdapi:deploy -d destructive -u <username> -w -1

You can perform a deployment that specifies components to delete in destructiveChanges.xml and components to add or update in package.xml. The process is the same as with performing a delete-only deployment except that package.xml contains the components to add or update.

By default, deletions are processed before component additions.

In API version 33.0 and later, you can specify components to be deleted before and after component additions. The process is the same as with performing a delete-only deployment except that the name of the deletion manifest file is different.

To delete components before adding or updating other components, create a manifest file that’s named destructiveChangesPre.xml and include the components to delete.

To delete components after adding or updating other components, create a manifest file that’s named destructiveChangesPost.xml and include the components to delete.

The ability to specify when deletions are processed is useful when you’re deleting components with dependencies.

On the Rename of Metadata ,only Metadata that supports CRUD based (You can use Metadata WSDL and check if components extend tns:Metadata) are supported in Metadata.Rename()

Since the SFDX CLI is based on jsforce and jsforce has excellent support for the Metadata API you can easily build a custom plugin for the salesforce dx cli if you want to use the rename command .

I just build one and you can install it using below

sfdx plugins:install mo-dx-plugin

Once you have it installed you can use below command,

sfdx metadata:rename --metadatatype CustomObject --oldfullname object1__c --newfullname objectnew__c
  • Awesome! Thanks very much for the detailed response! – infinityrobot Sep 9 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.