Wednesday, 11 April 2018

Rollback Code/Config Deployment from Production


There is NO Rollback available option for Change-sets in Salesforce. But many time we come across this situation where we need immediate rollback of Change-set we deployed in Production which is not possible in Salesforce.

But yes, there are possible ways where we can stop running the changes or roll back the changes easily.

Configuration Rollback

Configs like Validation rules, workflows, process builders etc. after deploying if you want to roll back the changes, easy way is to navigate to each newly deployed component/rule and deactivate it or delete it if it is not required which is time consuming.

What if there are thousands of them then it’s a tough work to do when you want this to be immediate.

In this case:

1.     Create a Custom Label with any name i.e. ActivateAllConfig
2.     Put the Label value as True.
3.     While checking for other required conditions in above rules, add condition check for ActivateAllConfig equals to true (AND operator).
4.     So, that it will execute only if the Label value is True.
5.     After deployment, to rollback all config changes in one shot you just have to make the Label value as False.
6.     All deployed rules will stop working.


Later if needed, we can just go to all deployed rule/component and change/deactivate/delete it from Production.


Code Class/Trigger Rollback

There are many ways -


Using Change-set

1.     Create a Change-set of apex changes you will be doing before any changes are made.
2.     Move it to production and validate the change-set and keep it.
3.     Create a Change-set (in Sandbox) after your changes, move, validate, deploy in Production.
4.     If you want Rollback any time you just deploy the previous validated Change-set so your back to the original code.  


Using Force.com IDE

1.     Use an IDE to create a new project and download all classes from production (take code back up).
2.     Identify the apex changes – classes, triggers.
3.     Save to server.

NOTE: There are lot of classes then it will take time to save to Server using IDE.


 Using Custom Label

1.     Custom label can be used the way we used for config keeping the value as True.
2.     We can add condition check in code using If condition while calling methods or before the block of code changes.
3.     So, just the Label value has to be changed to False when needed and the code will no longer execute in the org.


Using Custom Settings

If there is a situation where we want some code/class to execute and some of them to stop, there we can’t use single Custom Label for all and if we create multiple Labels, we will end up changing values for all Custom Labels used in all classes (different Labels for different classes).

In that case we can use Custom Settings with Field type Checkbox (checked/unchecked) or Text type (True/False).

1.     Create no. of Fields respective to each classes/Trigger with True/false values.
2.     Field Name can be kept as Class/Trigger name to identify the variables easily.
3.     To stop executing particular Class/Trigger, the Custom Setting field value has to be modified.
4.     Now, we can make the change to values to activate/deactivate the classes/Trigger within minutes.

There is possibility where you don’t need newly pushed class in Production anymore, there you need to delete the class using IDE, Ant etc.

Thanks!!


2 comments: