Generate a delta πŸ›† of your Salesforce ☁️ metadata for deployment πŸš€

benahm
4 min readMay 2, 2021
Generate a delta of your Salesforce metadata

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

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 πŸ‘

References

--

--

benahm

Salesforce Technical Architect πŸ‘·β€β™‚οΈβš’οΈπŸ’»β˜οΈ