ant migration tool

Salesforce Ant Migration Tool - The Complete Guide

Ant Migration Tool is one of the three tools available for Salesforce deployment and it is a totally Java based command line for moving metadata between one organization to another Salesforce organization.

Certain steps to be followed to discuss ANT Migration Tool:


  1. Java version 7 (1.7).
  2. Download the .zip file of the Spring '20 Ant Migration Tool.(or whatever be the latest at the time of using the Ant Migration Tool).
  3. Save the .zip file locally, and extract the contents to the directory of your choice.

 2. Required Orgs for Ant Migration Tool:

a.One is Source Org.

b.Another is Target Org.
dont miss out iconDon't forget to check out: Deployment In Salesforce

3.Certain steps to be followed to discuss ANT Migration Tool:

  1. Make a Connected App in your target org.(In Lightning Component i.e. Setup > Apps > App Manager > New Connected App.

a.Click on New Connected App and fill the details as per your needs & your callback URL looks like this

Don't forget to check out: Creating Wrapper Class in Salesforce Visualforce Pages


b.Just click on Save and you will see the Client Id and Client Secret key(Save that one, we will need it for Integration).

2. Create an Apex Class in Target Org to retrieve 10 Contacts  from Target Org. Go to Developer Console and create a new Apex Class.

global with sharing class Retrieve_10_contacts {
    global static list&lt;contact&gt; retrieve_10_contacts(){
        RestRequest req = RestContext.request;
        RestResponse res = Restcontext.response;
        List&lt;contact&gt; listContact =[Select Id , Name from Contact LIMIT 10 ];
        return listContact ;

3. Create a Remote Setting on Source Org. Search “Remote Site Setting” in Quick find Box and Enter Remote Site URL of your Target org, the format is like that –


4. Create an Apex Class in Source Org, which will callout Apex class of Target Org and return you 10 Contacts.

Here is the code-

public class GetAccountUsingRESTAPI {
    private final String clientId = 'XXXXXXXXXXXXXXXX';
    private final String clientSecret = 'XXXXXX8XXX';
    private final String username = 'SalesforceUserName';
    private final String password = 'Password';
    public class deserializeResponse
        public String id;
        public String access_token;
    public String ReturnAccessToken (GetContactUsingRESTAPI acount)
        String reqbody = 'grant_type=password&client_id='
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        HttpResponse res = h.send(req);
        deserializeResponse response = (deserializeResponse)JSON.deserialize(res.getbody(),deserializeResponse.class);
        system.debug('@@@@access_token@@'+response );
        return response.access_token;
    public static list callGetContact()
        GetAccountUsingRESTAPI contact1 = new GetContactUsingRESTAPI();
        String accessToken;
        accessToken = contact1 .ReturnAccessToken (contact1 );
        list ListContact=new List();
        if(accessToken != null){
            String endPoint = '';
            Http h2 = new Http();
            HttpRequest req1 = new HttpRequest();
            req1.setHeader('Authorization','Bearer ' + accessToken);

            HttpResponse res1 = h2.send(req1);
            String trimmedResponse = res1.getBody().unescapeCsv().remove('\\');

            JSONParser parser = JSON.createParser(res1.getBody());
            set conList=new set();

            while (parser.nextToken() != null) {

                if((parser.getCurrentToken() == JSONToken.FIELD_NAME) ){
                    Contact con;
                    if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == ‘Id’)) {
                        String sId= parser.getText();
                        con=new Contact();
                        system.debug(‘Id@@@’ + sId);

                        if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&
                        (parser.getText() == ‘Name’)) {

                            string sName= parser.getText();
                            system.debug(‘Name@@@’ + sName );
        return ListContact;

In the above code you will need to replace the following things:-

  • client
  • clientSecret
  • username
  • password

Also, Change the Endpoint in method ReturnAccessToken() in which org you are trying to log in. means where you have created your Connected Appreq.setEndpoint(‘’);

Also, Change the Endpoint in method callGetContact() in which org you are trying to access all the Contacts. means where you have developed your Apex RestService

String endPoint = ‘’;

Now call the function “callGetContact()”.

Feel free to ask questions in a comment box.


Happy Coding.

Popular Salesforce Blogs