Wednesday 15 November 2017

Salesforce Deployment Using ANT Migration Tool | ANT Deployment Tool

Please follow below step to configure Migration Tool ANT

Step 1) Install the Java

Please use 1.7x or later version for better security and for TLS security.

Migration using ANT in Salesforce

Step 2) Download the ANT

        1) Download ANT from below URL :-

        2) Download the zip file of Migration Tool from

       or you can click on STEP -> Tool -> Tools and Toolkits

salesforce ant migration jar

     Then Click on Migration Tool: and download the JAR file.

     Now We have below two zip files.

salesforce ant migration jar

     Unzip both the files.

       3) Now Open Migration Folder (salesforce_ant_41.0 in my case). and copy "" File and paste in apache-ant-1.10.1\lib folder "D:\ANTTool\apache-ant-1.10.1-bin\apache-ant-1.10.1\lib" .


Step 3) Set the path.

Now we need to set ANT_HOME and JAVA_HOME variable which we can set from Environment variable.

ANT_HOME   :- Set the address where you installed the ANT.
JAVA_HOME  :- set the value where your JDK is located.
Path  :- Set And and Jave path till bin folder

Now All Set. Check the version

Step 4) Configure "Build.xml" and "" Files

To setup connection with salesforce we need to configure the "".
  • Go to folder where you unzip the  Migration Tool Files. (in my case salesforce_ant_41.0 )
  • Open the "" and update like below 
  1. #

    # Specify the login credentials for the desired Salesforce organization
    sf.username =
    sf.password = Password

    sf.myDevusername =
    sf.myDevpassword = Password

    #sf.sessionId = <Insert your Salesforce session id here.  Use this or username/password above.  Cannot use both>
    #sf.pkgName = <Insert comma separated package names to be retrieved>
    #sf.zipFile = <Insert path of the zipfile to be retrieved>
    #sf.metadataType = <Insert metadata type name for which listMetadata or bulkRetrieve operations are to be performed>

    # Use '' for production or developer edition (the default if not specified).
    # Use ' for sandbox.
    sf.serverurl =

    sf.maxPoll = 20
    # If your network requires an HTTP proxy, see for configuration.

  • Now configure "build.xml" to retrievePkg and Deploy.

<project name="Sample usage of Salesforce Ant tasks" default="test" basedir="." xmlns:sf="antlib:com.salesforce">

    <property file=""/>
    <property environment="env"/>

    <!-- Setting default value for username, password and session id properties to empty string
         so unset values are treated as empty. Without this, ant expressions such as ${sf.username}
         will be treated literally.
    <condition property="sf.username" value=""> <not> <isset property="sf.username"/> </not> </condition>
    <condition property="sf.password" value=""> <not> <isset property="sf.password"/> </not> </condition>
    <condition property="sf.sessionId" value=""> <not> <isset property="sf.sessionId"/> </not> </condition>

    <taskdef resource="com/salesforce/antlib.xml" uri="antlib:com.salesforce">
            <pathelement location="../ant-salesforce.jar" />           
    <!-- Shows deploying code & running tests for code in directory -->
    <target name="deployCode">
      <!-- Upload the contents of the "codepkg" directory, running the tests for just 1 class -->
      <sf:deploy username="${sf.myDevusername}" password="${sf.myDevpassword}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" deployRoot="codepkg">
    <!-- Shows retrieving code; only succeeds if done after deployCode -->
    <target name="retrieveCode">
      <!-- Retrieve the contents listed in the file codepkg/package.xml into the codepkg directory -->
      <sf:retrieve username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" retrieveTarget="codepkg" unpackaged="codepkg/package.xml"/>


  • Now Setup your Package.xml file
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="">

Step 5) Now execute the command

 retrieve the Code from Source Salesforce org and execute below command

ant retrieveCode

Now Deploy the code to target Salesforce org

ant deployeCode

Reference :-

Amit Chaudhary