Force.com – The way to clean up code mess on Production while Deployment

Posted on

 

It is been a very interesting journey on the Cloud from the time I started working on Salesforce and Force.com Platform.

End of 2011 was the time where a Phase 2 of a Project started for one of my Clients in UK and I was assigned as the Technical Lead along with one more Associate to work with on the Project. I was all excited to take charge of this Project.

Important things to handle:

1) Provide Enhanced features

2) Improve the efficiency of the Code from Phase 1

3) Clean up the unwanted code during the process

Design, Development and Testing just like any other project, went through few hurdles. All of this was overcome successfully. I am limiting myself from explaining the details of the above process as I am particularly interested in writing more about one of the Critical part of the Project:DEPLOYMENT to Production.

Generally, there is an assumption from the Business Team and IT Management of the Company that, after all the design, development, system testing and UAT testing, it will be a smooth sail to do the Production Deployment, but there was something else waiting for us. Due to the enhancements and code clean up, we had to write different set of Test Code and delete some of the old code. Committing the new code was fine, but how do we remove the triggers, classes and anything else from Production that is no longer needed. We know that, we cannot do that using delete from Eclipse nor from the User Interface.

What other options did we have? Things that came t my mind first, making the trigger inactive, commenting unwanted code within the classes etc. But, I was not very happy about it. So, me and my other team member started looking into various other options. We used the ANT Deployment Process. But, wanted to see if there is an Undeployment Process. What do you think the answer? Yes, there was an option to do this. Not many forums had any details about it. We managed to find some source of information on the valuable Salesforce Developer Guides.

We managed to  find that, just like Deployment of Code using ANT, we can exclusively do Undeployment as well. Also don’t be surprised, we can deploy and undeploy using the same package.

For deployment, the folder used to deploy will consist of deploy folder (i.e., holding sub folders of Classes, Triggers, etc. along with package.xml file), then the build.xml and build.properties. With these things ready and going to the Command line, get to the deployment folder, we hit “ant deployCode”. This will complete the deployment process if all the unit test code is executed well.

Similarly, to undeploy any code from Production, we need to create a destructiveChanges.xml file (like package.xml file and specifiy the name and members that need to be deleted. Have removecodepkg folder consisting of the category of the folder with the files within to be deleted. Then run, “ant undeployCode”

To deploy and undeploy at the same time, merge the above folders and files together and then run, “ant undeployCode”.

 

After this, it is all about waiting for the Test Run to finish and validate deployment, finally when passed COMPLETE the DEPLOYMENT successfully.

Result: A Smiling Face and successful completion of the Project.