1

I need to remove the standard duplicate rules before deploying all my metadata into my scratch org. I am deploying my own duplicate rules so now the standard ones are useless. For production and other regular sandboxes I removed the standard duplicate rules manually; however, for my scratch orgs I would like to automate this. Do you know how to remove this duplicate rules? I thought it would be possible via the sfdx commands but I did not find any relevant command.

2
  • this might be complicated. First, you need to list all duplicate rules, generate destructiveChanges.xml, then use sfdx force:mdapi:deploy command to remove them
    – Patlatus
    Oct 1 at 13:20
  • can you simply put them into a separate folder and use .forceignore to ignore it?
    – ytiq
    Oct 1 at 13:56
2

Try the following bash script.

First, you need to list all duplicate rules, generate destructiveChanges.xml, then use sfdx force:mdapi:deploy command to remove them.

Create a file test.sh with this content

mkdir deploy
MY_XML="deploy/destructiveChanges.xml"
rm $MY_XML
rm "deploy/package.xml"

echo '<?xml version="1.0" encoding="UTF-8"?>\n<Package xmlns="http://soap.sforce.com/2006/04/metadata">\n<version>52.0</version>\n</Package>' >> "deploy/package.xml"


echo '<?xml version="1.0" encoding="UTF-8"?>\n' >> "$MY_XML"
echo '<Package xmlns="http://soap.sforce.com/2006/04/metadata">' >> "$MY_XML"
echo '    <types>' >> "$MY_XML"
for each in $(sfdx force:mdapi:listmetadata -m DuplicateRule --json | jq '.result[].fullName' -r); do
    echo "        <members>$each</members>" >> "$MY_XML"
done
echo '        <name>DuplicateRule</name>' >> "$MY_XML"
echo '    </types>' >> "$MY_XML"
echo '    <version>52.0</version>' >> "$MY_XML"
echo '</Package>' >> "$MY_XML"
sfdx force:mdapi:deploy -d deploy -w 500

Then execute this file

./test.sh

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.