An efficient implementation of Agile development for Force.com
We have been developing on the Force.com platform for nearly two years using the Agile software development methodology. We sometimes work simultaneously on different Force.com projects in our daily work.
Over time we have gained a lot of useful experience in developing for the Force.com platform using the Agile methodology. We have gained that experience by contributing to and delivering a large Enterprise application that runs on the Force.com platform as well as several smaller internal projects.
It will be assumed that you are familiar with the Agile development methodology and the concept of continuous delivery of useable software throughout the product development lifecycle.
We are constantly striving to automate as much of the continuous integration process with Force.com projects as possible. The Force.com platform provides unique challenges to creating a full continuous integration setup.
This article will describe some of the tools, methods and ideas that we use to make developing for Force.com as efficient and enjoyable as possible. More information on the tools and technologies that will be mentioned in this article can be found using the following links:
Summary of tools and technologies used
-
-
-
Force.com migration tool http://wiki.developerforce.com/page/Migration_Tool_Guide
-
Eclipse Force.com plugin or standalone Force.com IDE http://wiki.developerforce.com/page/Updating_the_Force.com_IDE
-
Google Chrome with Force.com Logins extension https://chrome.google.com/webstore/detail/forcecom-logins/ldjbglicecgnpkpdhpbogkednmmbebec#
Development environment setup
Here are some useful tips on setting up a development environment so that you can begin writing code and for deploying already-written code.
Acquisition of a clean development environment (or org/organisation from now on)
Acquiring a clean development org is not currently automatable, but is nevertheless very easy and is not a frequent operation in usual circumstances: http://www.developerforce.com/events/regular/registration.php
Org naming convention
If you’re regularly switching between orgs or logging into the orgs of other developers on your team, it is very helpful to have a simple naming convention for the different orgs. It is especially convenient to use as few characters as possible to distinguish each Developer Edition account. This speeds up tremendously the process of switching between orgs, either when you're logging in through the browser or setting up an Eclipse Force.com project.
Easy switching between Salesforce orgs with Google Chrome
There is a very useful extension for Google Chrome called Force.com Logins (see above for download and installation). This allows one to rapidly switch between different Salesforce orgs, which is a pretty regular need for most Salesforce users/developers.
‘Tearing down’ a Salesforce org
Since it is not possible to ‘tear down’ a Salesforce org, it is necessary to be able to ‘clean’ it instead before deploying other code. The Salesforce Migration Tool can be used to 'undeploy' meta-data from a Salesforce org - this action is where the Migration Tool comes in most useful as developers regularly want to reload the latest version or a different branch of code from a source repository into their environment.
Performing the ‘undeployment’ action using the Salesforce Migration Tool is pretty laborious - it requires the creation of a (using the default name from the available sample) destructiveChanges.xml file listing all of the components that you want to remove from the org. You also must know what is in the org in order to remove it - therefore you must ‘retrieve’ the components you want to remove beforehand and use a script to generate the destructiveChanges.xml file from the directory of retrieved components. The components to retrieve are specified by means of a ‘package.xml’ file, similar to the one for undeployment.
The above detailed cleaning steps can all be forgotten about when wrapped with a good script, which should in principle do the following:
-
The Salesforce Migration Tool is used to retrieve from the Salesforce org (whose credentials would be specified in the build.properties file) all of the metadata components that are declared in the package.xml file in the directory of the Salesforce Migration Tool. This is done by executing ant retrieveCode.
-
A script is used to generate a destructiveChanges.xml file that contains an explicit list (i.e. no wildcard characters) of all of the components of each type retrieved from the Salesforce org. The destructiveChanges.xml file follows the schema convention used in package.xml.
-
The 'undeploy' operation (ant undeployCode) is used to remove the metadata components listed in destructiveChanges.xml from the Salesforce org.
-
New code is downloaded from a source repository (e.g. GitHub) and source branch specified by the user and deployed into the Salesforce developer org (e.g. git clone -b <repository URL> <branch name> followed by ant deployCode).
Writing the code
Here are some tips and experiences on ways to accomplish the production of good quality Apex code in a time-efficient manner.
Source version control and branching
We use Git, hosted on Bitbucket, for source version control. We also use the following very useful source branching model: http://nvie.com/posts/a-successful-git-branching-model
We use Gitflow to implement the above branching model. We highly recommend Gitflow for saving a lot of finger-aching Git commands.
Eclipse and the Force.com IDE for Force.com development
The Eclipse Force.com IDE is currently the only IDE integrated with Salesforce for Force.com development. The Force.com IDE is also available as an Eclipse plugin. A developer can choose to develop either ‘online’ or ‘offline’ with the Force.com IDE.
Online vs. offline Force.com development
Online
Offline
Saving any change requires request/response interaction with Salesforce server
Saving a change is instant but is only saved locally and is not synced to the Salesforce environment.
Constant feedback on your code's compilation status, helping to ensure that the code is always in a good or working state.
Feedback given one error at a time when saving bulk changes later, leading to lengthy and frustrating bouts of code fixes.
Constant backing-up of your code on your Salesforce environment
Only copy is on your machine until you push to your distributed source repository (or similar)
Must use Force.com IDE for file editing
Free choice of method for editing files
Online or Offline development?
Amongst us, we have tried both of these methods with similar experiences. We find that the two result in similar productivity but that we prefer the ‘online’ method. The main reasons for preferring online over offline are that it is less stressful to fix compilation errors as they come up (rather than face an onslaught later) and that it is a safer way of working - since the latest version of your code is always in Salesforce as well as on your machine.
Deploying Apex code into a managed package
Managed packages are always created and always reside in Developer Edition environments - hence ‘packaging org’. Here are some tips for keeping a managed package in a consistent and correct state.
Maintaining a packaging org
Creation of a managed package involves creation of a ‘namespace prefix’ which is unique to that package and all versions of it. The managed package is also tied to the Developer Edition environment that it is created in. Thus for a given managed package, the final build will always be completed within the same environment.
Ideally, each release of an application is created in a clean development environment to ensure that there are no 'old' components of your project still sitting in there. Since that is not possible due to the details mentioned above, it is important to be careful and vigilant to ensure that the contents of the package are always consistent with what is on the release branch of your branching model.
Once package components (such as Apex classes, Visualforce pages) become managed, there can be problems with repeatedly deleting and re-deploying them into a developer environment. For example: attempting to re-deploy managed classes that have been previously deleted using the Salesforce Migration Tool can give the error: "Entity is deleted".
This can only be fixed by going to Your Name -> Setup -> Create -> Packages -> <package name> -> Deleted Components and manually clicking 'Undelete' for each one.
Due to the regular occurrence of this issue, you should only make ‘deploy' operations using the Salesforce Migration Tool on your packaging organisation and manually remove components like classes that are no longer used.
This means that you need a way to ensure that the code in your packaging org is the same as the code in your source repository. It is easy to do this using the Force.com IDE and Git:
-
Pull the latest code from your Github repo.
-
Create a Force.com project in Eclipse using the directory of the code just pulled.
-
Right-click on your project folder in Eclipse, then Force.com -> Refresh From Server. Providing your package.xml is set up to download the components that you want to update.
-
Run 'git status' in the project directory to reveal any changes made to your code by the ‘Refresh From Server’ operation above. You will see any changes that were downloaded from Salesforce.
Final comment
Hopefully some of the above ideas and solutions will provide assistance and value to other developers out there who may be beginning to develop for the Force.com platform. For more experienced developers I hope that this article may provide ideas for improving their development workflow.
Online
|
Offline
|
Saving any change requires request/response interaction with Salesforce server
|
Saving a change is instant but is only saved locally and is not synced to the Salesforce environment.
|
Constant feedback on your code's compilation status, helping to ensure that the code is always in a good or working state.
|
Feedback given one error at a time when saving bulk changes later, leading to lengthy and frustrating bouts of code fixes.
|
Constant backing-up of your code on your Salesforce environment
|
Only copy is on your machine until you push to your distributed source repository (or similar)
|
Must use Force.com IDE for file editing
|
Free choice of method for editing files
|
