String replacements provide a mechanism to manage environment-specific values in your Salesforce code without modifying source files. This feature automatically replaces placeholders with appropriate values during build, install, and push operations, and converts values back to placeholders during pull operations.
String replacements complement the existing aliasfy packages feature. While aliasfy packages handle structural metadata differences by deploying different files per environment, string replacements handle configuration value differences within the same files, reducing duplication and maintenance overhead.
How It Works
String replacements work across multiple sfp commands:
Build Operations: During sfp build, replacement configurations are analyzed and embedded in the artifact for later use during installation.
Install/Deploy Operations: During sfp install or sfp deploy, placeholders are replaced with environment-specific values based on the target org:
public class APIService {
private static final String ENDPOINT = '%%API_ENDPOINT%%';
private static final String API_KEY = '%%API_KEY%%';
}
public class APIService {
private static final String ENDPOINT = 'https://api-dev.example.com';
private static final String API_KEY = 'dev-key-12345';
}
β οΈ Potential replacements detected:
π src/package/main/default/classes/APIService.cls:
β’ URL detected: 'https://new-api.example.com/v2'
New URL pattern detected. Consider adding to replacements.yml
π‘ To include these values in future replacements, update your replacements.yml file.
# Check your org aliases
sf org list
# Push with specific org alias
sfp push -o dev-sandbox -p your-package
# Skip replacements during install
sfp install --targetorg dev --artifactdir artifacts --no-replacements
# Skip replacements during push
sfp push -p your-package -o dev --no-replacements
# Skip replacements during pull
sfp pull -p your-package -o dev --no-replacements
# Use override file during install
sfp install --targetorg dev --artifactdir artifacts --replacementsoverride custom-replacements.yml
# Use override file during push
sfp push -p your-package -o dev --replacementsoverride custom-replacements.yml
# Use override file during pull
sfp pull -p your-package -o dev --replacementsoverride custom-replacements.yml
# Get JSON output with replacement details
sfp push -p your-package -o dev --json
sfp pull -p your-package -o dev --json