I need to delete classes and a trigger from prod via VSCode. I have retrieved the according classes/trigger via package.xml into VSCode. There is the command "SFDX: Delete This from Project and Org", which I can only test with the classes/trigger from Prod and into Prod. Does anyone have experience with this functionality? Thanks!
1 Answer
The UI option currently does not support deletion of metadata from production (e.g. see this question) What you need to do is a normal metadata API deployment instead. Create a new folder in your project, then create two new files in this folder, package.xml and destructiveChanges.xml.
package.xml
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<version>48.0</version>
</Package>
destructiveChanges.xml
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>ClassToDelete</members>
<name>ApexClass</name>
</types>
<version>48.0</version>
</Package>
After saving these two files, you then need to run a mdapi deployment:
sfdx force:mdapi:deploy -d folderName -l RunLocalTests -s -w -1
Once complete, assuming no errors, the specified metadata will be deleted.
-
Thanks. How can I test this in a Sandbox first? Commented Mar 6, 2020 at 13:31
-
@user40501 Add the
-u username
option to the command, usesfdx force:config:set defaultusername=username
or specify the default connection in the UI inSFDX: Set a default org
. You need to authorize the sandbox before you can use that username (SFDX: Authorize an Org
orsfdx force:auth:web:login
).– sfdcfox ♦Commented Mar 6, 2020 at 13:35