1

One of the most time-consuming components of migrating an org to a new server is dealing with managed package references in permission sets and profiles. There can be hundreds or thousands of references per XML file. What is the best way to find and remove these references other than spending days searching and manually deleting?

1

First, I looked around for a tool that could automate this and then I started looking at search and replace functionality in dedicated XML editors. It looked like Oxygen could probably do the job but it was cost prohibitive for me. What I ended up doing was writing a regular expression and then using search and replace w/regex in Textmate (after trying a few other editors, including VSCode). The following are the regular expressions I used to eliminate all managed package references from permission sets and profiles:

<.+\s*<apexClass>mcdm_15\w*<.+\s*<.+\s*<\/classAccesses>
<.+\s*<.+\s*<field>mcdm_15\w*\.\w*<.+\s*<.+\s*<\/\w*>
<.+\s*<.+\s*<.+\s*<.+\s*<.+\s*<.+\s*<object>mcdm_15\w*<.+\s*<.+\s*<.+\s*<\/objectPermissions>
<.+\s*<tab>mcdm_15\w*s*<.+\s*<.+\s*<\/tabVisibilities>
<.+\s*<application>mcdm_15<.+\s+<.+\s+<.+\s+<\/applicationVisibilities>
<.+\s*<apexPage>tdc_tsw\w*<.+\s*<.+\s*<\/pageAccesses>

Textmate allows performing regular expression search and replace operations on entire directories, which meant that I could remove 20,000 managed package references from all profiles in less than a minute (either use version control or make a quick safety copy of the entire directory before each search and replace operation).

enter image description here

1

I built a command that cleans permission sets & profiles from unwanted items references in a sfdx project (should work on metadata project too)

For the moment it works with:

  • content of a destructiveChanges.xml file
  • data.com fields (CleanStatus etc...)
  • local fields (Contact.FirstNameLocal ...)
  • custom cleaning config file (destructiveChanges-like.xml or config.json)

Install & interactive clean type select:

npm i sfdx-hardis sfdx-essentials -g
sfdx hardis:project:clean:references

with custom config (with content of your managed package for example):

sfdx hardis:project:clean:references --config ./somefolder/myDestructivePackage.xml

Feel free to provide feedbacks and contribute :)

Note: this command is also available in VsCode SFDX Hardis extension

enter image description here

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.