Last active
October 3, 2019 18:30
-
-
Save sfdcale/2d84d2cb45d8d21f9252dd142a4ccf41 to your computer and use it in GitHub Desktop.
This shell script prepares package.xml file and downloads metadata in source format.
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 | |
| prepare_wildcard_package (){ | |
| echo " <types>" >> package_temp.xml | |
| echo " <members>*</members>" >> package_temp.xml | |
| echo " <name>$1</name>" >> package_temp.xml | |
| echo " </types>" >> package_temp.xml | |
| } | |
| rm -f temp.txt | |
| rm -f package_temp.xml | |
| echo "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n" >> package_temp.xml | |
| echo "<Package xmlns=\"http://soap.sforce.com/2006/04/metadata\">" >> package_temp.xml | |
| sfdx force:mdapi:listmetadata --metadatatype=EmailFolder --targetusername=$1 --json | jq '.result[].fullName' > temp.txt | |
| input="temp.txt" | |
| echo " <types>" >> package_temp.xml | |
| while IFS= read -r line | |
| do | |
| folderName="${line//\"/}" | |
| #folderName="'$id'" | |
| echo "$folderName" | |
| rm -f temp_1.txt | |
| sfdx force:mdapi:listmetadata --metadatatype=EmailTemplate --folder=$folderName --targetusername=$1 --json | jq '.result[].fullName' >> temp_1.txt | |
| while IFS= read -r line1 | |
| do | |
| templateName="${line1//\"/}" | |
| echo " <members>$templateName</members>" >> package_temp.xml | |
| done < "temp_1.txt" | |
| rm -f temp_1.txt | |
| done < "$input" | |
| echo " <name>EmailTemplate</name>" >> package_temp.xml | |
| echo " </types>" >> package_temp.xml | |
| rm -f temp.txt | |
| # this below section prepares package.xml for CustomObject type. | |
| echo " <types>" >> package_temp.xml | |
| sfdx force:mdapi:listmetadata --metadatatype=CustomObject --targetusername=$1 --json | jq '.result[].fullName' > temp.txt | |
| input="temp.txt" | |
| while IFS= read -r line | |
| do | |
| objName="${line//\"/}" | |
| echo " <members>$objName</members>" >> package_temp.xml | |
| done < "$input" | |
| echo " <name>CustomObject</name>" >> package_temp.xml | |
| echo " </types>" >> package_temp.xml | |
| rm -f temp.txt | |
| #this below section prepares package.xml for Layout. | |
| echo " <types>" >> package_temp.xml | |
| sfdx force:mdapi:listmetadata --metadatatype=Layout --targetusername=$1 --json | jq '.result[]' | jq '"\(.fullName)____\(.manageableState)____\(.namespacePrefix)"' > temp.txt | |
| input="temp.txt" | |
| while IFS= read -r line | |
| do | |
| line="${line//\"/}" | |
| layoutType=$(awk -F'____' '{print $2}' <<< $line) # this gives whether it is installed or unmanaged | |
| if [ $layoutType == "installed" ] | |
| then | |
| fullLayoutName=$(awk -F'____' '{print $1}' <<< $line) | |
| objName=$(awk -F'-' '{print $1}' <<< $fullLayoutName) | |
| layOutName=$(awk -F'-' '{print $2}' <<< $fullLayoutName) | |
| nameSpacePrefix=$(awk -F'____' '{print $3}' <<< $line) | |
| fixedLayoutName=$objName-$nameSpacePrefix"__"$layOutName | |
| echo " <members>$fixedLayoutName</members>" >> package_temp.xml | |
| else | |
| fullLayoutName=$(awk -F'____' '{print $1}' <<< $line) | |
| echo " <members>$fullLayoutName</members>" >> package_temp.xml | |
| fi | |
| done < "$input" | |
| echo " <name>Layout</name>" >> package_temp.xml | |
| echo " </types>" >> package_temp.xml | |
| rm -f temp.txt | |
| prepare_wildcard_package ApexClass | |
| prepare_wildcard_package ApexTrigger | |
| prepare_wildcard_package ApexComponent | |
| prepare_wildcard_package ApexPage | |
| prepare_wildcard_package AuraDefinitionBundle | |
| prepare_wildcard_package LightningComponentBundle | |
| prepare_wildcard_package Flow | |
| prepare_wildcard_package CustomMetadata | |
| echo " <version>46.0</version>" >> package_temp.xml | |
| echo "</Package>" >> package_temp.xml | |
| cat package_temp.xml | |
| sfdx force:source:retrieve --targetusername=$1 --manifest=package_temp.xml | |
| rm -f force-app/main/default/flows/dat_case_closure_survey.flow-meta.xml | |
| rm -f force-app/main/default/objects/Survey/listViews/My\ Surveys.listView-meta.xml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment