-
-
Save sfdcale/4b7bbc55f359192dc6d33bcd1debf382 to your computer and use it in GitHub Desktop.
SFDX script to retrieve profiles and perm sets with object CRUD and FLS
This file contains hidden or 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/bash | |
| TARGET_ORG=$1 | |
| if [$TARGET_ORG == ""]; then | |
| echo Please specify a target username | |
| echo For a list of available usernames use: sfdx force:org:list | |
| exit 1 | |
| fi | |
| rm -rf temp | |
| mkdir temp | |
| cd temp | |
| # package.xml | |
| echo '<?xml version="1.0" encoding="UTF-8"?>' > package.xml | |
| echo '<Package xmlns="http://soap.sforce.com/2006/04/metadata">' >> package.xml | |
| # Profiles | |
| sfdx force:mdapi:listmetadata -m Profile -u $TARGET_ORG -f Profiles.json | |
| echo "<types>" > Profiles.txt | |
| cat Profiles.json | jq '[.[].fullName] | sort | .[] | "<members>" + . + "</members>"' -r >> Profiles.txt | |
| echo "<name>Profile</name></types>" >> Profiles.txt | |
| cat Profiles.txt >> package.xml | |
| # PermissionSet | |
| sfdx force:mdapi:listmetadata -m PermissionSet -u $TARGET_ORG -f PermissionSets.json | |
| echo "<types>" > PermissionSets.txt | |
| cat PermissionSets.json | jq '[.[].fullName] | sort | .[] | "<members>" + . + "</members>"' -r >> PermissionSets.txt | |
| echo "<name>PermissionSet</name></types>" >> PermissionSets.txt | |
| cat PermissionSets.txt >> package.xml | |
| # Custom Objects | |
| sfdx force:mdapi:listmetadata -m CustomObject -u $TARGET_ORG -f CustomObjects.json | |
| echo "<types>" > CustomObjects.txt | |
| cat CustomObjects.json | jq '[.[].fullName] | sort | .[] | "<members>" + . + "</members>"' -r >> CustomObjects.txt | |
| echo "<name>CustomObject</name></types>" >> CustomObjects.txt | |
| cat CustomObjects.txt >> package.xml | |
| echo '<version>45.0</version>' >> package.xml | |
| echo '</Package>' >> package.xml | |
| # retrieve metadata | |
| sfdx force:mdapi:retrieve -s -k package.xml -r ./ -u $TARGET_ORG | |
| unzip unpackaged.zip -d $TARGET_ORG | |
| rm unpackaged.zip | |
| cd .. | |
| mkdir retrieve | |
| mv temp/$TARGET_ORG retrieve/ | |
| rm -rf temp |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
run the script as below:
sh script.sh <username of the org>