ant migration tool salesforce

Ant migration tool

ANT Migration tool is a command-line utility to retrieve, deploy or delete metadata from a Salesforce Org. With the Salesforce Ant Migration tool, you can migrate metadata between local files and Salesforce org. It helps you migrate Metadata information such as Objects/Reports/Apex Classes/Visualforce Pages/Aura components between different Salesforce environments. After the configuration, ANT allows you to move Metadata from one Salesforce environment to another quickly.

Configuring The Ant Migration Tool:

  1. Download JDK from https://www.oracle.com/technetwork/java/javase/downloads/index.html
  2. After installation, we can verify the version by open Command Prompt and using the java -version.
  1. Download Apache Ant version 1.6 or later from http://ant.apache.org/bindownload.cgi.
  2. Now we need to extract the zip file. To create a new folder and extract a zip file.
  1. Download the zip file of the Spring 19 release from here: https://gs0.salesforce.com/dwnld/SfdcAnt/salesforce_ant_45.0.zip
  2. Extract the downloaded zip to a folder where we extracted the Apache Ant.
  • Right-click on the ‘This PC’ – Properties – Advanced System Setting.
  • Click Environment Variables
  • Now Add two variables ANT_HOME and JAVE_HOME.
  • Click on the new add variable name and their respective path for both the User and System variables
  • Now you need to make sure that both the path of ant and java JDK should be available in the system’s path variable and user variable. If it is not available, then add both paths.

Step to Retrieve information:

1.Go to the location where you extracted the Ant Migration Tool files.

2.Open the Salesforce_ant_50.0 Folder and open the Sample Folder

3.Now open the Build properfile

4.Open the Build properties file and enter your credential from where we need to retrieve information and the URL of the org.

  1. Set sfSup.username & sfSup.password with your sandbox credentials.
  2. Set sf.username & sf.password with your Sandbox/Production credentials.
  3. Note that, you need to enter the password along with 25-digit security token of your respective orgs. Please see below
  4. Set sf.serverurl = https://login.salesforce.com(production)
  5. Set sfSup.serverurl = https://test.salesforce.com(sandbox)
  6. And sf.maxPoll = 20Save the file and close

Build.xml

  1. Open the “build.xml” file, edit/modify the existing “target” tags or create/write new one as per the below highlighted ones.
  2. First, set the default conditions (see highlighted)
  3. Second, set the “retrieveUnpackaged” target tag to pull all components as metadata from Sandbox and save it in the folder path “D:\Test\codepkg”
  4. Third , set the “validateCodePkg” target tag to check whether we can successfully deploy the pulled metadata components into the production environment or not. It will list you the challenges to address if failed during deployment
  5. Fourth, set the “deployCodePkg” target tag to deploy the pulled metadata components into the production environment. It will list you the challenges to address if failed during deployment. Please see below.
  6. Now, you are all set to migrate the metadata components to production.

5. After this, we need to open another file.

6. Follow the path Salesforce_ant_50.0 -> Sample -> codepkg.

7. Now open the package with notepad++

8. Now you can edit the file which you want to retrieve.

9.(a) If you want to retrieve everything, you need to describe the type and name of the information.

9. (b)If you want to retrieve the particular information, you need to describe as below

Pulling all metadata components from Sandbox using command Prompt or Windows PowerShell

(I used Windows PowerShell here)

1.Type “Windows PowerShell” in “Windows” search box and right click on the powershell to run as administrator, you will get a prompt page like the below

2.Now, you need to go into the directory where you want to run the commands, like type “cd D:\Test” and press enter

3.Type “ant retrieveUnpackaged” in prompt page and press enter

  • If it is successful, you will see the components pulled in the mentioned file path. Please see above. Otherwise, it will throw errors that should be addressed and try pulling again.
  • Note: I used one testclass and trigger for example, and in your case, you may see folders of whatever components you have written in the “package.xml” file
  • If you want to just check whether you can successfully deploy the components or not, type “ant validateCodePkg” in the powershell prompt
  • Or if you want to just deploy the components, type “ant deployCodePkg” in the powershell prompt. Please see below.

4. Based on the actions performed, you will get the results like the below

Great work! You have successfully completed migrating metadata components from Sandbox to Production using “Ant Migration Tool”

Thank you for giving this blog content Murugavel

https://www.linkedin.com/in/murugavel-kannan-6837801b3

Leave a Comment

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