Using the Migration Tool

In addition to the IDE, you can also use a script to deploy Apex.

Download the Migration Tool if you want to perform a file-based deployment of metadata changes and Apex classes from a Developer Edition or sandbox organization to a production organization using Apache's Ant build tool.

The Migration Tool is a free resource provided by Salesforce to support its users and partners but isn't considered part of our services for purposes of the Salesforce Master Subscription Agreement.
To use the Migration Tool, do the following:
  1. Visit and install Java JDK, Version 6.1 or greater on the deployment machine.
  2. Visit and install Apache Ant, Version 1.6 or greater on the deployment machine.
  3. Set up the environment variables (such as ANT_HOME, JAVA_HOME, and PATH) as specified in the Ant Installation Guide at
  4. Verify that the JDK and Ant are installed correctly by opening a command prompt, and entering ant –version. Your output should look something like this:
    Apache Ant version 1.7.0 compiled on December 13 2006
  5. Log in to Salesforce on your deployment machine. From Setup, click Develop | Tools, then click Migration Tool.
  6. Unzip the downloaded file to the directory of your choice. The Zip file contains the following:
    • A Readme.html file that explains how to use the tools
    • A Jar file containing the ant task: ant-salesforce.jar
    • A sample folder containing:
      • A codepkg\classes folder that contains SampleDeployClass.cls and SampleFailingTestClass.cls
      • A codepkg\triggers folder that contains SampleAccountTrigger.trigger
      • A mypkg\objects folder that contains the custom objects used in the examples
      • A removecodepkg folder that contains XML files for removing the examples from your organization
      • A sample file that you must edit, specifying your credentials, in order to run the sample ant tasks in build.xml
      • A sample build.xml file, that exercises the deploy and retrieveAPI calls
  7. If you installed a previous version of this tool and copied the ant-salesforce.jar file to the ant lib directory, delete this jar file from the lib directory. The ant lib directory is located in the root folder of your Ant installation. The Migration Tool uses the ant-salesforce.jar file that's in the distribution zip and you no longer need to copy this file to the ant lib directory.
  8. Open the sample subdirectory in the unzipped file.
  9. Edit the file:
    1. Enter your Salesforce production organization username and password for the sf.user and sf.password fields, respectively.
      • The username you specify should have the authority to edit Apex.
      • If you are using the Migration Tool from an untrusted network, append a security token to the password. To learn more about security tokens, see “Resetting Your Security Token” in the Salesforce online help.
    2. If you are deploying to a sandbox organization, change the sf.serverurl field to
  10. Open a command window in the sample directory.
  11. Enter ant deployCode. This runs the deployAPI call, using the sample class and Account trigger provided with the Migration Tool.

    The ant deployCode calls the Ant target named deploy in the build.xml file.

    <!-- Shows deploying code & running tests for package 'codepkg' -->
        <target name="deployCode">
          <!-- Upload the contents of the "codepkg" package, running the tests for just 1 class -->
          <sf:deploy username="${sf.username}" password="${sf.password}" serverurl="${sf.serverurl}" deployroot="codepkg">

    For more information on deploy, see Understanding deploy.

  12. To remove the test class and trigger added as part of the execution of ant deployCode, enter the following in the command window: ant undeployCode.

    ant undeployCode calls the Ant target named undeployCode in the build.xml file.

    <target name="undeployCode">
          <sf:deploy username="${sf.username}" password="${sf.password}" serverurl=
                "${sf.serverurl}" deployroot="removecodepkg"/>
See the Migration Tool Guide for full details about the Migration Tool.
© Copyright 2000–2015, inc. All rights reserved.
Various trademarks held by their respective owners.