Last active
February 15, 2024 18:45
-
-
Save benahm/b590ecf575ff3c42265425233a2d727e to your computer and use it in GitHub Desktop.
Deploy a destructive change using the Salesforce CLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# author : benahm | |
# description : deploy a destructive change | |
# inputs | |
TARGET_ENV=$1 | |
SOURCE_PATH=$2 | |
# constants | |
API_VERSION=47.0 # api version (same as in the sfdx-project.json) | |
DEFAULT_TEST_CLASS=MyTestClass # a passing test class | |
echo "Clean existing destructivePackage folder" | |
rm -rf deployment/destructivePackage &>/dev/null | |
mkdir -p deployment/destructivePackage &>/dev/null | |
echo "Converting Source format to Metadata API format" | |
sfdx force:source:convert -p ${SOURCE_PATH} -d deployment/destructivePackage | |
# copy package.xml to desctructiveChanges.xml | |
cp deployment/destructivePackage/package.xml deployment/destructivePackage/destructiveChanges.xml | |
# generate an empty (containing only the api version tag) package.xml | |
cat <<EOT > deployment/destructivePackage/package.xml | |
<?xml version="1.0" encoding="UTF-8"?> | |
<Package xmlns="http://soap.sforce.com/2006/04/metadata"> | |
<version>${API_VERSION}</version> | |
</Package> | |
EOT | |
# deploying to the target org | |
echo "Deploying a destructive change to ${TARGET_ENV}" | |
echo "In Progress..." | |
sfdx force:mdapi:deploy -d deployment/destructivePackage -u ${TARGET_ENV} -l RunSpecifiedTests -r ${DEFAULT_TEST_CLASS} -w -1 | |
if [ $? -eq 0 ]; then | |
# green color | |
echo -e "\e[32m************************** Success **************************" | |
else | |
# red color | |
echo -e "\e[31m************************** Error **************************" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment