Newer Version Available
Using the Ant Migration Tool
In addition to the Force.com IDE, you can also use a script to deploy Apex.
Download the Ant 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.
To use the Ant Migration Tool, do the following:
- Visit http://www.oracle.com/technetwork/java/javase/downloads/index.html and install the Java JDK.
- Visit http://ant.apache.org/ and install Apache Ant, Version 1.6 or later, on the deployment machine.
- Set up the environment variables (such as ANT_HOME, JAVA_HOME, and PATH) as specified in the Ant Installation Guide at http://ant.apache.org/manual/install.html.
- 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:
1Apache Ant version 1.7.0 compiled on December 13 2006 - Download the .zip file of the Spring '19 Ant Migration Tool. The download link doesn’t require authentication to Salesforce. If you’re logged in to Salesforce, we recommend you log out before accessing the link in your browser.
- 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 build.properties 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 retrieve API calls
- The Ant Migration Tool uses the ant-salesforce.jar file that’s in the distribution .zip file. If you installed a previous version of the tool and copied ant-salesforce.jar to the Ant lib directory, delete the previous jar file. The lib directory is located in the root folder of your Ant installation. You don’t need to copy the new jar file to the Ant lib directory.
- Open the sample subdirectory in the unzipped file.
- Edit the build.properties file:
- Enter your Salesforce production organization username and password for the sf.user and sf.password fields, respectively.
- If you are deploying to a sandbox organization, change the sf.serverurl field to https://test.salesforce.com.
- Open a command window in the sample directory.
- Enter ant deployCode. This runs the deploy API call, using the sample class and Account
trigger provided with the Ant Migration Tool.
The ant deployCode calls the Ant target named deploy in the build.xml file.
1<!-- Shows deploying code & running tests for package 'codepkg' --> 2 <target name="deployCode"> 3 <!-- Upload the contents of the "codepkg" package, running the tests for just 1 class --> 4 <sf:deploy username="${sf.username}" password="${sf.password}" serverurl="${sf.serverurl}" deployroot="codepkg"> 5 <runTest>SampleDeployClass</runTest> 6 </sf:deploy> 7 </target>For more information, see Understanding deploy.
- 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.
1<target name="undeployCode"> 2 <sf:deploy username="${sf.username}" password="${sf.password}" serverurl= 3 "${sf.serverurl}" deployroot="removecodepkg"/> 4</target>