03 August 2014

REVIEW: FAST Deploy using Force.com Ant Migration Toolkit

One of the pain points when deploying components in Salesforce regardless if you use ChangeSet, Force.com IDE or ANT is the fact that it runs all test classes in your Production environment if one of the components being deployed are one of the following metadata types (as per the metadata api document developer guide v31).

  • ApexClass
  • ApexComponent
  • ApexPage
  • ApexTrigger
  • ArticleType
  • BaseSharingRule
  • CriteriaBasedSharingRule
  • CustomDataType
  • CustomField
  • CustomObject
  • DataCategoryGroup
  • Flow
  • InstalledPackage
  • NamedFilter
  • OwnerSharingRule
  • PermissionSet
  • Profile
  • Queue
  • RecordType
  • RemoteSiteSetting
  • Role
  • SharingReason
  • Territory
  • Validation Rule
  • Workflow
Now imagine if your environment contains a huge amount of customization. This would mean you might have hundreds to thousands of apex test classes that are being run every time you deploy. The time it takes to run all of these test classes depends on how optimized the codes and test classes were written and I have experienced waiting for 4 hours for a couple hundred of apex codes to be deployed to Production.

Introducing FAST Deploy (Pilot)


FAST Deploy allows admins to specify specific test classes to run during deployment and the current instance I'm supporting was fortunate enough to be a part of the program and I could say that it really provides good value specially to administrators. The duration of our deployments are now cut from hours to minutes. 

How to use FAST Deploy (Pilot)


The following are the prerequisites:
  1. The instance should be a part of the pilot program (contact your account manager).
  2. Currently this is only possible when using the ANT Migration Toolkit.
If you are familiar with ANT Migration scripting then it is fairly easy, otherwise you can learn more in this link. You just need to add a new <runTest> node on your <sf:deploy> from the build.xml of your ANT script. See example below:


<target name="deployCode">
<sf:deploy username="${sf.username}"
password="${sf.password}" serverurl="${sf.serverurl}"
maxPoll="${sf.maxPoll}" deployRoot="codepkg">
<runTest>TestClassName1</runTest>
<runTest>NameSpace.TestClassName2</runTest>
</sf:deploy>
</target>

Here's a screen shot of a sample deployment from Setup -> Deploy -> Deployment Status section. Most of the components here are apex codes and custom fields but the deployment only ran 12 test methods and took only 5 minutes.



There are a few caveats though on using the feature:

  • The test classes specified to run must cover 75% code coverage for each apex triggers/classes in the package.xml.
  • Aggregate code coverage from different test classes are not counted. For example, if 1 test class covers 50% of an apex trigger and another test class covers 25% for the same trigger, if both test classes are run, this is not considered as 75%.
  • As mentioned above, all these are only possible using Force.com ANT migration toolkit.
As this only runs a subset of the test classes from the environment, I recommend administrators to ensure that all test classes are run from time to time to get the overall code coverage from the environment.