Last active
February 4, 2020 14:26
-
-
Save aaronallport/08b3a163af17fca35dd0dbd150b5008e to your computer and use it in GitHub Desktop.
Salesforce bash script stubs to do common or mundane tasks
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/bash | |
# Stub shell script to spin up metadata files. Modify it to suit your needs :-) | |
# ./SF_GenerateMetadata.sh <input_csv_file>.csv | |
# example format of CSV: label,fieldapiname__c,value | |
INPUT=$1 | |
OLDIFS=$IFS | |
IFS=',' | |
[ ! -f $INPUT ] && {echo "$INPUT not found"; exit 99; } | |
while read label item2 item3 | |
do | |
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?> | |
<CustomMetadata xmlns=\"https://soap.sforce.com/2006/04/metadata\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"> | |
<label>$label</label> | |
<protected>false</protected> | |
<values> | |
<field>__FIELD_NAME_ITEM_2__c__</field> | |
<value xsi:type=\"xsd:string\">$item2</value> | |
</values> | |
<values> | |
<field>__FIELD_NAME_ITEM_3__c__</field> | |
<value xsi:type=\"xsd:string\">$item3</value> | |
</values> | |
</CustomMetadata>" > ./out/__FILE_NAME__.$label.md-meta.xml | |
done < $INPUT | |
IFS=$OLDIFS |
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/bash | |
# Stub shell script to spin up metadata files. Modify it to suit your needs :-) | |
# ./tokenise_metadata.sh <input_csv_file>.csv | |
# example format of CSV: workflow,__TOKEN_TO_FIND__,valueToReplaceTheTokenWith | |
INPUT=$1 | |
OLDIFS=$IFS | |
IFS=',' | |
[ ! -f $INPUT ] && {echo "$INPUT not found"; exit 99; } | |
while read metadataName tokenToFind valueToSubstitute | |
do | |
# Strip out the trailing carriage return/new-line character | |
valueToSubstitute="$(echo $valueToSubstitute | sed 's/$//')" | |
for file in ./force-app/main/defualt/$metdataName/* | |
do | |
echo Tokenising $file | |
sed -i "s/$tokenToFind/$valueToSubstitute/g" "$file" | |
done | |
done < $INPUT | |
IFS=$OLDIFS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment