Generate a delta π of your Salesforce βοΈ metadata for deployment π
Few releases ago, Salesforce βοΈ introduced the packaged-based π¦ approach (see second-generation packaging) for managing & deploying metadata, but unfortunately, many legacy projects π are still using the unpackaged ποΈ deployment.
The goal π― of this article π° is to present an sfdx plugin 𧩠that simplifies the unpackaged deployment by generating a delta package of the modified metadata from the git commits history π
Why use a plugin to generate deltas πΊ
If you donβt use an sfdx plugin to generate a delta based on the git diff, that means youβll have to do :
- Full deployment (SLOW βΉοΈ): deploying all the tracked metadata takes time β±οΈ on each deployment and for a highly customized org there is a risk to hit the metadata API limits
- Manually select metadata (TEDIOUS βΉοΈ): manually β selecting the metadata takes time β±οΈ for your developers π», they have to prepare the package or package.xml in order to deploy only the modified metadata
Note ποΈ: in both cases, you have to prepare a destructive package in order to remove the deleted ποΈ metadata, because otherwise you have to delete them manually in the target org
Introducing the βsfdx-mdt-pluginβ
sfdx-mdt-plugin is a Salesforce βοΈ CLI plugin 𧩠that Iβve created and open-sourced π on Github π, It contains several commands βοΈ, but here will only focus on the git:delta command.
The mdt:git:delta uses the git diff to automatically detect the modified/deleted files in order to generate a :
- Delta πΊ package that contains all the modified metadata
- Destructive ποΈ package that contains the deleted metadata
the advantage of this command compared to the existing ones on github, is that mdt:git:delta support a deep π diff on the following complex metadata types
- Record Types
- Custom Labels
- Profiles
- Sharing Rules
- Assignment Rules
- Auto-Response Rules
- Matching Rules
- Translations
- Workflows
That means that for example, when you update ποΈ just one access to a field in a profile π, the delta file generated will contain the profile file π§Ύ with the only updated field access
Install the sfdx-mdt-plugin π₯
Run the following command
sfdx plugins:install sfdx-mdt-plugin
The plugin is not digitally signed π, click yes to continue π
How to use the plugin βοΈ
the command supports the following parameters
-f : (required) commit or branch name from which to do the diff
-t : commit or branch name to which to do the diff (default is HEAD)
-p : (required) folder name where to generate the delta package
-d : folder name where to generate the destructive package (will not be generated if not specified)
Run the following command to generate the deltas :
sfdx mdt:git:delta -f {fromCommit} -t {toCommit} -p {deltaPackagePath} -d {destructivePackagePath}
Then you can deploy the delta package using the following sfdx command
sfdx force:source:deploy -p {deltaPackagePath} -u {targetOrg}
And the destructive package using this command
sfdx force:source:delete -r -p {destructivePackagePath} -u {targetOrg}
Note : force:source:delete is not supported in production, youβll need to convert the destructive package into metadata format and use the force:mdapi:deploy to deploy it
Disclaimer β οΈ: this sfdx plugin is just a piece of software πΎ that Iβve coded using my fingers β, all commanded by my brain π§ π , so it can contain bugs π, please report any issue in the GitHub π issue tab, thanks π