Skip to content

Instantly share code, notes, and snippets.

@Damecek
Created October 7, 2023 19:20
Show Gist options
  • Select an option

  • Save Damecek/769392ce93e7d1ee17e5e9b09a3ef790 to your computer and use it in GitHub Desktop.

Select an option

Save Damecek/769392ce93e7d1ee17e5e9b09a3ef790 to your computer and use it in GitHub Desktop.
Deploy fields from permission set metadata
#!/bin/bash
# Usage
# /bin/bash ./deployPermSetFields.sh ./force-app/main/default/permissionsets/Logistic_Edit.permissionset-meta.xml
# Get the XML file name from the script argument
xml_file=$1
# Use awk to extract field names
fields=$(awk -F'[<>]' '/<field>/ {print $3}' $xml_file)
# Start constructing the package.xml manifest file
echo '<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>' > package.xml
# Iterate over the fields and add them to the package.xml file
IFS=$'\n' # Set Internal Field Separator to newline for iteration
for field in $fields; do
object_name=$(echo $field | cut -d'.' -f1) # Assuming the field name is formatted as Object.Field
field_name=$(echo $field | cut -d'.' -f2)
echo " <members>$object_name.$field_name</members>" >> package.xml
done
# Finish constructing the package.xml manifest file
echo ' <name>CustomField</name>
</types>
<version>52.0</version>
</Package>' >> package.xml
cat package.xml
echo 'Deploying metadata to Salesforce...'
# Deploy the metadata using the sf CLI tool
sf project deploy start -x package.xml --verbose --ignore-conflicts
# Delete the package.xml file after deployment
rm package.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment