Guide to Complete Deployment of Salesforce using the Ant Migration Tool

An organization can use three ways to move its schema, objects, code and other elements to another organization:

·         Salesforce change sets found on the Salesforce site

Union workers rolling out the Salesforce cloud sign

·         Using Eclipse

·         Using ANT which is a Java tool

The following is a sequential discussion of the migration process if you are using the third method, i.e. the ANT migration.

Precondition

Organization must have Java Development Kit 1.5 and higher

Step #1:

 The ANT distribution is downloadable online.

Step #2:

The environment variable called “ANT_HOME” should be set. The correct path is the path of the parent folder that stores the “bin” above. Add the “bin” folder to this path also.

Step #3:

Determine whether you properly installed the ANT migration tool. To do this, run the command “ant –version”. If by chance, you get the notification that the tools.jar file cannot be found the file may be copied from “JDK_HOME/lib/tool.jar” and into the “JRE/lib” folder.

Step #4:

Log in to salesforce.com. Download “force.com Migration Toolkit”. The file downloads as a zipped folder, which you can unzip to any directory that you want. From this folder, copy the “ant-salesforce.jar” to the directory (ANT lib’s).

To begin deployment on ANT, two files are necessary: “build.properties” and “build.xml”. You may not need the former, but it is advisable to create it all the same, because settings related to configuration are stored in a different file. From the folder which you unzipped the downloaded file to, both of these files can be copied. The block of code for “build.properties” is provided below”

1     # build.properties

2     # stipulate login authorizations for the Salesforce enterprise desired

3     sf.username = <SFDCUserName>

4     sf.password = <SFDCPasswrd>

5     #sf.pkgName = <put in package names that you want to retrieve, separated by commas>

6     #sf.zipFile = <Put in the directory path of the zipped file to be retrieved>

7     #sf.metadataType = <Pu in the metadata type name on which bulkRetrieve or listMetadata operations will performed>

8     # Use ‘ https://login.salesforce.com ‘ for developer or production edition (if the default has not been specified).

9     # Use ‘ https://test.salesforce.com ‘ for sandbox.

10    sf.serverurl = https://test.salesforce.com

Then proceed to step 5.

Step #5:

Replicate all the folders containing code from the sender organization (called the source) by using Eclipse. Use the above extract of code to create a “build.properties” file, or copy from the unzipped folder location. Next, you will need to create a file called “build.xml” which is required by the ANT tool.

There is an attribute “deployRoot” which refers to the root where from the code is to be copied while a tag <runTest> refers to the text classes that are supposed to run after deployment is complete. Finally, run the command “ant deployCode” from the command prompt, referring to the location of the root folder. 

Deleting components using the “desctructivechanges.xml

Sometimes, you may need to delete specific components e.g. field or objects from the Salesforce organization database. In such cases, “packge.xml” alone will not work – you also need to create the “destructiveChanges.xml” file. The syntax is the same, except that it does not define wildcards, unlike in “pakcages.xml”. Both files are necessary to un-deploy any component from Salesforce.

Author Bio

Tony Simmons is an expert in Salesforce with over 7 years experience in the IT industry. For more information or enquiries on the force.com migration toolkit and other aspects of release management, visit his website.

Comments are closed.