Source Control for Salesforce
What is Source Control?One of the most important tools in any software development stack is a version control system, also known as source control. Source control is a way of “versioning” software and tracking changes to a code base over time.
Source control is not only where you store your code but also where you track changes that are made to it. It’s also the key collaboration tool for any software development team. Let’s say developer A and developer B are working on the same code base. Source control is what let’s them make changes in a safe way without overwriting each other’s work.
There are a number of tools that you can use for source control like SVN and Git. Git is the most popular and fastest growing.
Why Doesn’t Salesforce Include Source Control Natively?Salesforce is an amazing tool. Much of what makes Salesforce awesome is that it is possible do complex application development without needing to know how to code. The whole “clicks not code” paradigm is very powerful and enables people who are not Salesforce developers to build great tools.
The Force.com platform - which is tailored more specifically to programmers - is also amazing. Tools like Apex, Visualforce and Lightning make it possible to take Salesforce even further through custom code.
Unfortunately, Salesforce's philosphy around “clicks not code” has prevented it from nailing a few key software development best practices. The Salesforce Org has always been the system of record rather than any source control system. This is a problem because the Org is not a good source of truth. You can’t see what’s changed on it over time and you can’t see who has made changes.
Moreover the Force.com platform, for all it’s merits, is not designed to handle merge conflicts. It is all too easy for Salesforce developers to overwrite one another’s code.
Why is Source Control Important for Salesforce Developers?Force.com is a real development platform. As such, you must use source control in order to use the platform well. You will not find a team of Node.js or Django or Ruby on Rails developers writing code without using a versioning system of some kind. And it will likely be Git that they are using.
Whether you know it or not, your team may not be operating at full capacity if you don’t have a version control system.
A Good Sign You May Need a Source Control SystemHas this ever happened to you? You spend weeks working on a feature. You go to the Force.com IDE and push it up to your production or UAT environment. Shortly after that one of your teammates pushes another change and completely overwrites what you’ve worked on? Your version control system is your saving grace here - it will help you visualize what has changed so you can go back and undo the work that was clobbered by your colleague.
But a good source control system like Git will take it one step further. It won’t let your code be overwritten in the first place. Git has a way of handling “merge conflicts” which will require you to address discrepancies in the code before deploying so that you don’t overwrite another developers work.
This is especially important in the Force.com plaform beause it’s not just developers who affect code. Admins are able to make changes to the code base using the Salesforce developer console. A good version control solution will account for this unique aspect of the Force.com platform. Many Salesforce teams have a good Org setup: they use sandboxes or developer editions for development, UAT or staging for testing and only push to production after going through testing on the staging environment.
However the more complex this setup, the easier it is to run into problems with collaboration. If you’re not careful this is where it can be common for developers and admins to start overwriting each other or running into merge conflicts.
Salesforce Audit TrailSalesforce's audit trail functionality unfortunately only provides limited number of records. For compliance and other reaons, it can be useful to have a longer history of changes.
Another key reason that Salesforce developers need version control is keeping a clear record of what has happened on your Org over time. Who made a change? When did they make it? And what precisely was the change? What is different between the code on Sandbox A and Sandbox B?
With a good version control system like Git and Blue Canvas you will be able to see that Jane Doe made a change to this Apex Class or Visualforce Page on October 4th at 2:30pm. That kind of granularity is crucial for a number of reasons.
First, it helps with debugging. Seeing a history of an Apex Class or Workflow rule is a great way to understand how the code has evolved over time. This makes it easier to fix bugs that pop up. This is especially useful on old Salesforce implementations where the original code may have been written long ago by an employee or contractor who is long gone.
It’s also useful to be able to see what is happening on the Org before doing a major release. Many release managers are flying blind today and a good version control system will help provide visibility that can prevent catastrophe. Git gives you a line by line look at precisely what has changed in your code base.
Salesforce Code ReviewsThis line by line look makes it possible to do one of the most valuable practices in software development today: code reviews. Code reviews matter for a number of reasons. Code reviews catch obvious flaws in logic and prevent bugs. They also help ensure conventions are being followed so that everyone can work comfortably and seamlessly across the entire code base. A good code review system will also ensure that your entire team is familiar with different parts of the code base. This is great so that no one team member is the only person that knows why a Apex Class was written the way it was.
A good version control system is essential for doing code reviews because it will show you what has changed and where.
Salesforce DXSalesforce DX is a new program from Salesforce which will alter the way Salesforce developers and admins think about deploying their code. In order to take advantage of Salesforce DX, teams must move towards source driven development. Going forward, Salesforce developers will be asked to move their code and metadata under version control for the reasons stated above. However, Salesforce DX does not make any assumptions about or prefer any particular version control system. Teams will have to choose and implement their ow source control system to use Salesforce DX.
How Blue Canvas Makes Source Control for Salesforce EasyGit is an amazing tool but it’s not always easy to implement. This is especially true for Salesforce.
Blue Canvas makes it possible for every member of your team - admins, product managers, developers, release managers, business analysts and the like - to leverage the power of Git without requiring them to make a lot of changes to how they work on a daily basis.
Blue Canvas automatically tracks declarative changes made through the UI in Git. So if an admin or a developer makes a change to an Apex Class or Workflow Rule through the Force.com developer console, Blue Canvas will automatically log that to Git. There is no need to do a commit.
Blue Canvas also handles merge conflicts between developers and admins in a powerful way. Blue Canvas will not let you deploy code that hasn’t been properly merged and will show you exactly where you need to address merge conflicts. So it is no longer possible to overwrite people’s changes.
Blue Canvas is based on standard Git. If you are a power user you can do anything that you could do with Git with Blue Canvas. You can pull changes from your Orgs into your local environment. You can also run
git diffin order to see what has changed between your Orgs.
Version Control Will Improve Your Force.com Code QualityThe meta reason for investing in a source control system is simple: it will dramatically improve the code quality of your Force.com applications. It will enable your developers and admins to collaborate more safely. And it will empower your team to move significantly faster than it is today.
Force.com, for all it’s merits, doesn’t make it easy to implement a comprehensive version control solution. Blue Canvas can help with this.