Rollback Based on Snapshots Differences
When you want to roll back your changes, you can do it by following the instructions provided in the Copado Rollback article, but you can also do it by running snapshots differences.
There are some cases in which you may need to perform the rollback through Snapshot Differences:
- Changes were made directly in an environment, without using promotions or deployments.
- You want to rollback changes in an environment for which you have not activated the promotion-based Rollback feature (such as non-business-critical or developer environments).
- You have deployed changes to an environment by using any of the deployment steps not supported in the Rollback feature (see supported steps in the Copado Rollback article).
To run snapshot differences, you will need to perform some steps before and after the deployment.
Before a Deployment
A prerequisite for performing rollbacks is to have a backup of your org in a branch in your Git repository. We recommend scheduling frequent backups by using Copado scheduled jobs, or every time you deploy changes to the org.
For frequent backups, you can do the following:
- Create a backup branch in the Git repository for the relevant working branch. For example, for the master/main branch, create a “master_backup” or “main_backup” branch.
- Create a Git Snapshot record in Copado and fill in the details as follows:
- Enter a descriptive name, like 'Production Backup'.
- Select your Git repository.
- Enter the backup branch name. In our example 'master_backup'.
- In the Git Snapshots Permission field, select Allow Snapshots Only. This will prevent anyone from committing to this branch and altering the backup version.
- Select a frequency to schedule the backup on a daily or weekly basis, depending on how often you deploy to that org.
- In the Org Credential field, select the org from where the metadata will be retrieved. In this example, select production since you are backing up from master:
Alternatively, if you want to execute a backup only for specific deployments, create a URL Callout step in the Deployment record prior to the actual Git Promotion step. Select the Take a Git Snapshot webhook and select the backup Git snapshot to be executed, or simply open the backup Git Snapshot record and click on Take Snapshot Now to manually perform the backup.
After a Deployment
In order to compare files and execute the rollback, follow these steps:
- Create a snapshot difference to compare the latest backup commit in the backup branch (master_backup in this example), against the destination org:
- Once the difference calculation is finished, select the files that you would like to deploy to the destination org:
- Click on Create Deployment and then follow the steps to deploy the metadata components from the Git backup.
- Delete corresponds to components that were created during the latest deployment, but don’t exist in the latest backup. They will be deleted in destination if selected.
- Create corresponds to components that were deleted in the destination org during the last deployment, but are available in the latest backup. They will be created in the destination if selected.
- Update corresponds to components that were modified/updated during the last deployment. By using the Show Diff link you can see a side-by-side comparison of the files:
- Once the deployment is successfully completed, go to the Git Snapshot record of the destination org (production in our example), click on Commit Changes and select the metadata components that were rolled back and commit them. This will ensure that the changes in the org's branch are in sync with the org itself.
Given the way Salesforce handles some of the metadata, items which should be deleted are disregarded. Although fields or workflow rules/actions can be selected as single metadata elements, they will be added to one big object definition or object workflow file (e.g. Opportunity.object or Opportunity.workflow). The items that are added to those files will be created, but if an item (e.g. a field) is removed from the file, and this file is deployed (Opportunity.object), Salesforce will disregard the field instead of deleting it.
In order to make sure these items are deleted, you will need to add a Delete Metadata step with the items to be deleted to the deployment resulting from the snapshot difference.
The following elements are sample metadata which handle deletions of nested components/references:
- Custom Report Types
The following elements are sample metadata which disregard deletions of nested components/references:
- Any metadata you can construct atomically, but which in the background is stored in one single file.
For more information about the metadata types, check out the article Commit Changes Overview.