Salesforce ANT

Here in this post we will learn about ANT and  How To Deploying Salesforce Data Using ANT . when and how to use it .

In salesforce to migrate data from sandbox to production we  use changeset. but  with project complexity deployment with changeset become  more complex.  It is good if we know others deployment options that salesforce provides.

Some of the options for deployment are:

  1. Eclipse IDE
  2.  Changeset
  3. Ant
  4.  Custom Tool

Here in this post we will learn about  ANT Migration Tool.

ANT Migration Tool:   The Ant Migration Tool is a Java/Ant-based command-line utility for moving metadata between a local directory and a Salesforce org.

ANT uses xml Instructions to perform the actions.  So to use ANT you need basic knowledge of xml and ANT Commands available.

Here are the steps one should follow :

  1.  Download And Installation
  2.  Set Environment Variable
  3.  Test Installation
  4.  Retreive And Deploy Code
  5.  See Deployment Changes by log in into your org.

1.  Download And Installation.

Before you can use the Ant Migration Tool, Java and Ant must be installed and configured correctly. If you already have Java and Ant on your computer, you don’t need to install them, so first verify the installation from a command prompt.

To check the version of Java that’s installed on your system:
1. Open a command prompt.
2. At the prompt, type java -version and press Enter.

To check the version of ANT that’s installed on your system:
1. Open a command prompt.
2. At the prompt, type ANT -version and press Enter.

If java And ANT are not installed in your computer  then download and install java and ANT.

You need java(JDE/JRE) before install  ANT so you need to first install Java in your system.

After installing Java(JDE/JRE) Now Install ANT Migration Tool in your system.

Install The Ant Migration Tool

Follow these steps to download and install the Ant Migration Tool.

If you don’t have Ant installed, Follow the below steps to download ANT Migration Tool.
1. Download the .zip file of the Winter ’18 Ant Migration Tool. (You can also download a .zip file containing a preview version of the
Spring ’18 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.
2. Save the .zip file locally, and extract the contents to the directory of your choice.

After Extract you find out the below folder structure or files . the following folders and files are written to the location you specified:
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

2. Set Environment Variable

  • We Need  To set the enviornment path variable. we Set Enviornment path variable because  it help us to acess ant tool  from any folder through the command line.
  • Create a ANT_HOME and JAVA_HOME in your system advanced properties section.
  •  Sometimes we get confused to set  path variables  make sure  that you have installed java and ANT before setting variables.
  • ADD JDK,JRE and ANT home folder path to OS PATH Variable
  • Example : Ex: PATH = C:\Users\Himanshu\Data\Softwares/ant/bin;      C:\Users\Himanshu\Data\Softwares/java/jdk\bin  C:\Users\Himanshu\Data\Softwares/java/jre\bin;
  •  Now we create ANT_HOME and JAVA_HOME in your system advanced properties section.

3. Test Installation

  • Once We  Setup all the things now its time to check everything is working fine.
  •  Test Instalation by  open command prompt and type ant – version  for ant installation test. And java – version for java installation test
  •  If ANT is successfully configured  you see the message  you have successfully  configured the ANT.  otherwise your ant  installation was not successfull or enviornment variable  were not set successfully.

 Now all the things are set  now we  will move on and see how all the things work with salesforce.

  •  Let’s understand the  important files available in salesforce ant folder.

Ant.build.xml :  The main file that containing all the task performed. here in this file all the task are available we might  want ant to perform  for our porject. Example: deploy or retrieve  in a specific format.

When you give  ant a command, it will read the built.xml configuration file, searching for the target match the name you specified in your command when it finds  , it will execute.

build.xml example:

<project name="Sample usage of Salesforce Ant tasks" default="test" basedir="." xmlns:sf="antlib:com.salesforce">
<property file="build.properties"/>
<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">
<classpath>
<pathelement location="../ant-salesforce.jar" />          
</classpath>
</taskdef>
<!-- Test out deploy and retrieve verbs for package 'mypkg' -->
<target name="test">
<!-- Upload the contents of the "mypkg" package -->
<sf:deploy username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" deployRoot="mypkg" rollbackOnError="true"/>
<mkdir dir="retrieveOutput"/>
<!-- Retrieve the contents into another directory -->
<sf:retrieve username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" retrieveTarget="retrieveOutput" packageNames="MyPkg"/>
</target>
<!-- Retrieve an unpackaged set of metadata from your org -->
<!-- The file unpackaged/package.xml lists what is to be retrieved -->
<target name="retrieveUnpackaged">
<mkdir dir="retrieveUnpackaged"/>
<!-- Retrieve the contents into another directory -->
<sf:retrieve username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" retrieveTarget="retrieveUnpackaged" unpackaged="codepkg/package.xml"/>
</target>
<!-- Retrieve all the items of a particular metadata type -->
<target name="bulkRetrieve">
<sf:bulkRetrieve username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" metadataType="${sf.metadataType}" retrieveTarget="retrieveUnpackaged"/>
</target>
<!-- Retrieve metadata for all the packages specified under packageNames -->
<target name="retrievePkg">
<sf:retrieve username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" retrieveTarget="retrieveOutput" packageNames="${sf.pkgName}"/>
</target>
<!-- Deploy the unpackaged set of metadata retrieved with retrieveUnpackaged and run tests in this organization's namespace only-->
<target name="deployUnpackaged">
<sf:deploy username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" deployRoot="retrieveUnpackaged" rollbackOnError="true"/>
</target>
<!-- Deploy a zip of metadata files to the org -->
<target name="deployZip">
<sf:deploy username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" zipFile="${sf.zipFile}" pollWaitMillis="1000" rollbackOnError="true"/>
</target>
<!-- 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.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" deployRoot="codepkg" testLevel="RunLocalTests" rollbackOnError="true">
</sf:deploy>
</target>
<!-- Shows deploying code with no TestLevel sepcified -->
<target name="deployCodeNoTestLevelSpecified">
<sf:deploy username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" deployRoot="codepkg" rollbackOnError="true"/>
</target>
<!-- Shows deploying code and running tests only within the org namespace -->
<target name="deployCodeRunLocalTests">
<sf:deploy username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" deployRoot="codepkg" rollbackOnError="true"  testlevel="RunLocalTests"/>
</target>
<!-- Shows removing code; only succeeds if done after deployCode -->
<target name="undeployCode">
<sf:deploy username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" deployRoot="removecodepkg"/>
</target>
<!-- 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"/>
</target>
<!-- Shows deploying code, running all tests, and running tests (1 of which fails), and logging. -->
<target name="deployCodeFailingTest">
<!-- Upload the contents of the "codepkg" package, running all tests -->
<sf:deploy username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" deployRoot="codepkg" testLevel="RunAllTestsInOrg" rollbackOnError="true" logType="Debugonly"/>
</target>
<!-- Shows check only; never actually saves to the server -->
<target name="deployCodeCheckOnly">
<sf:deploy username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" deployRoot="codepkg" checkOnly="true"/>
</target>
<!-- Shows quick deployment of recent validation. Set the property sf.recentValidationId to your recent check only deployment Id -->
<target name="quickDeploy">
<sf:deployRecentValidation  username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" recentValidationId="${sf.recentValidationId}"/>
</target>
<!-- Shows cancel deployment of deploy request either pending or in progress. Set property sf.requestId to Id of pending or in progress deploy request -->
<target name="cancelDeploy">
<sf:cancelDeploy  username="${sf.username}" password="${sf.password}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" requestId="${sf.requestId}"/>
</target>
<!-- Retrieve the information of all items of a particular metadata type -->
<target name="listMetadata">
<sf:listMetadata username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" metadataType="${sf.metadataType}"/>
</target>
<!-- Retrieve the information on all supported metadata type -->
<target name="describeMetadata">
<sf:describeMetadata username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}"/>
</target>
<!-- code to retreive a package -->
<target name="himanshuPackage">
<sf:retrieve 
username="${sf.username}" 
password="${sf.password}"
sessionId="${sf.sessionId}" 
serverurl="${sf.serverurl}" 
retrieveTarget="codepkg" 
packageNames="ant_TEST"/>
</target>
</project>

build.properties:   This files connect  ANT to our target salesforce instance. In This file  we specify salesforce instance details like username,password, access token etc.

Here is  how build.properties look like.

# build.properties
#
# Specify the login credentials for the desired Salesforce organization
sf.username = your org username
sf.password = salesforce org 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 'https://login.salesforce.com' for production or developer edition (the default if not specified).
# Use 'https://test.salesforce.com for sandbox.
sf.serverurl = https://login.salesforce.com
sf.maxPoll = 20
# If your network requires an HTTP proxy, see http://ant.apache.org/manual/proxy.html for configuration.
#

Package.xml:  This File Contains  The info about  what all classes, triggers ,pages, objects you  want to deploy  or retrieve.

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>AccountDateUpdate_Test</members>
<name>ApexClass</name>
</types>
<types>
<members>accountdateupdatebyopportunity</members>
<name>ApexTrigger</name>
</types>
<version>41.0</version>
</Package>

 Retreive And Deploying Salesforce Data Using ANT

In This example we will migrate  salesforce package  containing trigger with  test class.

we Retreive a package containing  trigger and test class  from salesforce by using the below steps:

as we discuss earlier  there are  three important files we need to retreive and deploy code  now by using these files we retreive  data from salesforce org.

Here are the steps:

1)Specify salesforce instance details like username,password, access token etc. We specify these details in build.properties file.

build.properties:   This files connect  ANT to our target salesforce instance. In This file  we specify salesforce instance details like username,password, access token etc.

here is our build.properties file example.

# build.properties
#
# Specify the login credentials for the desired Salesforce organization
<!-- sert username and password --->
sf.username = test@user.com
sf.password = testpassword
#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 'https://login.salesforce.com' for production or developer edition (the default if not specified).
# Use 'https://test.salesforce.com for sandbox.
sf.serverurl = https://login.salesforce.com
sf.maxPoll = 20
# If your network requires an HTTP proxy, see http://ant.apache.org/manual/proxy.html for configuration.
#

2) Now we specify  the task performed. We specify these details in Ant.build.xml  or build.xml file.

Ant.build.xml :  The main file that containing all the task performed. here in this file all the task are available we might  want ant to perform  for our porject. Example: deploy or retrieve  in a specific format.

Ant.build.xml Example:

<project name="Sample usage of Salesforce Ant tasks" default="test" basedir="." xmlns:sf="antlib:com.salesforce">
<property file="build.properties"/>
<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">
<classpath>
<pathelement location="../ant-salesforce.jar" />          
</classpath>
</taskdef>
<!-- Test out deploy and retrieve verbs for package 'mypkg' -->
<target name="test">
<!-- Upload the contents of the "mypkg" package -->
<sf:deploy username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" deployRoot="mypkg" rollbackOnError="true"/>
<mkdir dir="retrieveOutput"/>
<!-- Retrieve the contents into another directory -->
<sf:retrieve username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" retrieveTarget="retrieveOutput" packageNames="MyPkg"/>
</target>
<!-- Retrieve an unpackaged set of metadata from your org -->
<!-- The file unpackaged/package.xml lists what is to be retrieved -->
<target name="retrieveUnpackaged">
<mkdir dir="retrieveUnpackaged"/>
<!-- Retrieve the contents into another directory -->
<sf:retrieve username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" retrieveTarget="retrieveUnpackaged" unpackaged="codepkg/package.xml"/>
</target>
<!-- Retrieve all the items of a particular metadata type -->
<target name="bulkRetrieve">
<sf:bulkRetrieve username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" metadataType="${sf.metadataType}" retrieveTarget="retrieveUnpackaged"/>
</target>
<!-- Retrieve metadata for all the packages specified under packageNames -->
<target name="retrievePkg">
<sf:retrieve username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" retrieveTarget="retrieveOutput" packageNames="${sf.pkgName}"/>
</target>
<!-- Deploy the unpackaged set of metadata retrieved with retrieveUnpackaged and run tests in this organization's namespace only-->
<target name="deployUnpackaged">
<sf:deploy username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" deployRoot="retrieveUnpackaged" rollbackOnError="true"/>
</target>
<!-- Deploy a zip of metadata files to the org -->
<target name="deployZip">
<sf:deploy username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" zipFile="${sf.zipFile}" pollWaitMillis="1000" rollbackOnError="true"/>
</target>
<!-- 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.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" deployRoot="codepkg" testLevel="RunLocalTests" rollbackOnError="true">
</sf:deploy>
</target>
<!-- Shows deploying code with no TestLevel sepcified -->
<target name="deployCodeNoTestLevelSpecified">
<sf:deploy username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" deployRoot="codepkg" rollbackOnError="true"/>
</target>
<!-- Shows deploying code and running tests only within the org namespace -->
<target name="deployCodeRunLocalTests">
<sf:deploy username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" deployRoot="codepkg" rollbackOnError="true"  testlevel="RunLocalTests"/>
</target>
<!-- Shows removing code; only succeeds if done after deployCode -->
<target name="undeployCode">
<sf:deploy username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" deployRoot="removecodepkg"/>
</target>
<!-- 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"/>
</target>
<!-- Shows deploying code, running all tests, and running tests (1 of which fails), and logging. -->
<target name="deployCodeFailingTest">
<!-- Upload the contents of the "codepkg" package, running all tests -->
<sf:deploy username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" deployRoot="codepkg" testLevel="RunAllTestsInOrg" rollbackOnError="true" logType="Debugonly"/>
</target>
<!-- Shows check only; never actually saves to the server -->
<target name="deployCodeCheckOnly">
<sf:deploy username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" deployRoot="codepkg" checkOnly="true"/>
</target>
<!-- Shows quick deployment of recent validation. Set the property sf.recentValidationId to your recent check only deployment Id -->
<target name="quickDeploy">
<sf:deployRecentValidation  username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" recentValidationId="${sf.recentValidationId}"/>
</target>
<!-- Shows cancel deployment of deploy request either pending or in progress. Set property sf.requestId to Id of pending or in progress deploy request -->
<target name="cancelDeploy">
<sf:cancelDeploy  username="${sf.username}" password="${sf.password}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" requestId="${sf.requestId}"/>
</target>
<!-- Retrieve the information of all items of a particular metadata type -->
<target name="listMetadata">
<sf:listMetadata username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" metadataType="${sf.metadataType}"/>
</target>
<!-- Retrieve the information on all supported metadata type -->
<target name="describeMetadata">
<sf:describeMetadata username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}"/>
</target>

<!-- code to retreive a package -->
<target name="testPackage">
<sf:retrieve 
username="${sf.username}" 
password="${sf.password}"
sessionId="${sf.sessionId}" 
serverurl="${sf.serverurl}" 
retrieveTarget="codepkg" 
packageNames="ant_TEST"/>
</target>
</project>
<!-- code to deploy a package -->
<target name="deployPackaged">
<sf:deploy 
username="${sf.username}" 
password="${sf.password}" 
sessionId="${sf.sessionId}"
serverurl="${sf.serverurl}" 
deployroot="salestingpkg"/>
</target>

In the above file we specify code to retreive and upload  a package  . there are different properties lets  explain them one by one.

 Code we add to our ant.build.xml file to retrieve package .

<target name="testPackage">
<sf:retrieve username="${sf.username}"
password="${sf.password}"
sessionId="${sf.sessionId}"
serverurl="${sf.serverurl}"
retrieveTarget="codepkg"
packageNames="ant_TEST"/>
</target>

Code we add to our ant.build.xml file to deploy package .

<target name="deployPackaged">
<sf:deploy 
username="${sf.username}" 
password="${sf.password}" 
sessionId="${sf.sessionId}"
serverurl="${sf.serverurl}" 
deployroot="salestingpkg"/>
</target>

Now I am explaining above code snippet . here are the important  points

targetname :  It specify the command we use in our command prompt to execute our configuration file.

When you give  ant a command, it will read the built.xml configuration file, searching for the target match the name you specified in your command when it finds  , it will execute.

username && Password : to specify username . we donot need to change this code because we already specify username and password in build.properties

session id && Serverurl :  These variables are set in build.properties no need to change this code .

retrieveTarget :   holds the name of the folder  in which we want to store our package after   retreiving from salesforce.

packageNames :  holds the name of the salesforce package you want to retreive from salesforce.

3)  Specify The info about  what all classes, triggers ,pages, objects you  want to deploy  or retrieve. for this we use

Package.xml:  This File Contains  The info about  what all classes, triggers ,pages, objects you  want to deploy  or retrieve.

here in this file we define  memebers and there type we are fetching .

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>AccountDateUpdate_Test</members>
<name>ApexClass</name>
</types>
<types>
<members>accountdateupdatebyopportunity</members>
<name>ApexTrigger</name>
</types>
<version>41.0</version>
</Package>

4)  Now we  retreive code from our salesforce org to do this, open the command prompt and navigate to the path directory  you want to  retrieve the code.

and then execute the command we  specify in our  ANt.buid.xml file . so i execute  ant himanshuPackage command here as i specify this command in our file earlier.

ant
if you see any error like :  build.xml does not exist.

check the path you specified always specified the path of the folder in which your build.xml  file exist.

here in below command is specified the folder in which my build.xml exist that is

c:\users\wake’n’code\downloads\salesforce_ant_41.0\cd sample

after then  I execute command ant himanshuPackage for download package  And  deploy package to deploy a package ( this is the command I specify earlier  in my  build.xml file).

ant

5. Monitor Changes by loggin to your account.

After completion of all the steps you can see the changes in your org by logged in .

to monitor   your deployment go to  deployment status in your  salesforce Org you see something like below  screenshot if deployment successed.

Deployment

Hits: 3201

Share Post

By Himanshu Rana

My Name is Himanshu Rana, 23 Years young, born and grow up in Ghaziabad, India. A High Spirited Salesforce Admin, Developer and a Blogger. I currently work at Wakencode Technologies,

8 thoughts on “Deploying Salesforce Data Using ANT”
  1. Oh my goodness! Awesome article dude! Thanks, However
    I am going through difficulties with your RSS.

    I don’t know why I am unable to join it.

    Is there anyone else having identical RSS issues?

    Anyone who knows the solution can you kindly respond?
    Thanks!!

  2. When I initially commented I clicked the “Notify me when new comments are added” checkbox
    and now each time a comment is added I get several e-mails with the same comment.

    Is there any way you can remove people from that service? Cheers!

  3. I would like to thank you for the efforts you have put in writing this website.
    I’m hoping to see the same high-grade blog posts by you
    later on as well. In fact, your creative writing
    abilities has inspired me to get my own, personal blog now 😉

  4. You really make it seem so easy with your presentation but I find this matter to be really something which I think I would never understand.

    It seems too complex and extremely broad for me.
    I’m looking forward for your next post, I’ll try to get the hang
    of it!

Leave a Reply

Your email address will not be published. Required fields are marked *