Showing posts with label Force.com ANT. Show all posts
Showing posts with label Force.com ANT. Show all posts

07 December 2016

Installing Force.com Migration Toolkit on Mac


In this blogpost, I will provide the steps on how I installed the Force.com Migration Toolkit on my MacBook with MacOS Sierra 10.12.1.

INSTALL ANT ON YOUR MAC

Step 1: If you Mac is not pre-installed with ANT you will need to download it. Go to the Apache website and download the latest tar.gz version as depicted below:


Step 2: Once downloaded, extract the files by double-clicking the downloaded archived file and saving the extracted folder into a path of your choosing. I added it on my user path ~/Users/<user_name>/apache-ant-1.9.7 



Step 3: Add the ANT path to the environment variable so that it can be called from any location in terminal. To do this we need to edit .bash_profile and export the ANT path. First, execute the command below and save the path it will give:

echo $PATH


Then open .bash_profile using the nano terminal text editor by executing the following command:

nano .bash_profile

Create the ANT_HOME variable and append it to the path retrieved earlier using colon:

export ANT_HOME=<location_of_the_extracted_ant_files>
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$ANT_HOME/bin

The editor should look like below:



Verify that you can call ant by executing ant -v



INSTALL FORCE.COM MIGRATION TOOLKIT

Step 1: Download the toolkit from the salesforce developer website

Step 2: Once downloaded, extract files by double-clicking it

Step 3: Copy ant-salesforce.jar on your ANT lib folder

Thats it! Test if its working using the sample ant script provided from the force.com migration toolkit.




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.