Monday, December 9, 2019

How to Setup ANT for Salesforce with Proxy settings


Hello Friends,

Many developers are facing the issue of setting up ANT Migration Tool for Salesforce with Proxy Settings. Today, I have jotted down all the steps to setup this tool.

Steps:
1.      Download the Apache ANT from the google.

2.      Unzip it and put it any drive. Let’s say, for example D drive. You can keep the name as ANT_HOME(Optional).
proxy




3.       Download the zip file from the Salesforce website and place it anywhere like desktop:

proxy

4.      Unzip the step-3 downloaded file and copy the "ant-salesforce" JAR file to the lib folder where you have copy pasted the ANT_HOME folder as shown below:
proxy


5.      Now, install JDK and install it in C drive.
proxy


          6.     You need to set the Path in the environmental variable
          Right click My Computer and click on properties.
          Click on Advanced System Settings on the left panel.
            A new popup window will show up and click on Environment Variables.
            Now you can set JAVA and ANT path.
            Create one System Variables with JAVA_HOME and give the path till bin folder of JAVA JDK as given below:
                            proxy

            Once the JAVA_HOME variable is set, click on path and then click edit.
            Add two things as shown below as per location:
            %JAVA_HOME%\bin will copied as it is.
proxy

             7.         All Set! Next thing is to test the ANT setup in the command prompt.
             8.       Type ant -version and you should see the below response:
proxy

             9.       Congratulations!!

                                   DATA Retrieval and Deployment

          Retrieval
1.       Now it’s time to retrieve the data from salesforce org.
2.       Open the sample folder as shown in step-4.
3.       There you will see two most important files for configuring the ANT.
3.1       Build Properties
3.1.1 This file contains the login information like salesforce username and password and the connecting salesforce org.proxy

3.1.2 Provide your username of salesforce and password along with the security token.

3.1.3 If your company is having any sort of proxy setting then you may need to write additional code in this file.

proxy.host = <your company host>
proxy.port = <your company port>
proxy.user = <your company’s username>
proxy.pwd = <your company’s password>

3.1.4         If there are no firewall or proxy settings from your company then you can skip the above step.
3.1.5         You are done with the configuration of Build.Properties file.

3.2       Build.xml
3.2.1 Modifications are required if you want to do some proxy related things or else you can skip this.
3.2.2 Add the below code in the end of the file and enter the value in each tag:
        <target name="proxy">
        <property name="proxy.host" value="" />
        <property name="proxy.port" value="" />
        <!--If there username and password required -->
                                <property name="proxy.user" value=" " />
        <property name="proxy.pwd" value=" " />
        <setproxy proxyhost="${proxy.host}" proxyport="${proxy.port}" proxyuser="${proxy.user}" proxypassword="${proxy.pwd}" />
      </target>
proxy

3.2.3 Now add the keyword “depends="proxy” in the target tag like shown below:
proxy

3.2.4         So, this keyword will be added to all the commands in the build.xml which you are going to use for migration like retrievePkg, deployUnpackaged. If this is not added, then you will get an Error while retrieving: Failed to send request to https://test.salesforce.com/services/Soap/u/47.0

3.2.5         Now you are good to go.

4.       Open Command Prompt and enter the directory sample as defined in Step-3 and keep this aside.
proxy


5.       Open the folder unpackaged and open package.xml.
6.       Create a similar package like show below as per your requirments
proxy

7.       Package is ready and it’s time to do some magic.
8.       Write the command ant retrieveUnpackaged on the command prompt.
proxy

9.       Proxy user will see their proxy username and non-proxy user will not see this.
10.   After successful run you will see a new folder in your sample directory with name as retrieveUnpackaged
proxy

11.   Open this folder and you will find the components which you have entered in the package in step-6.

Deployment

1.       You need to be very careful, while deploying the components to the other environments.
2.       Firstly, change the username and password in build.properties file and give the target org’s credentials.
3.       Change the sf.serverurl to the target org’s URL and save it.
4.       Open the command prompt and type ant deployUnpackaged.
5.       Your components will be deployed to the other environment.
6.       If there is any error, it will rollback.


Kindly Share your feedback and let me know if there are any issues!

Do let me know your views on this.




9 comments:

  1. Great information, thanks for the help👍

    ReplyDelete
  2. Hello all,

    just a question. I have a build.xml file with several targets.
    I define one target in Jenkins but since the default in build.xml is different, always run the default and ignore the target defined in the job in Jenkins. If i change the default it will run the new target. Anyone know what can be the root cause to ignore Jenkins configuration?
    Thank you.

    ReplyDelete
  3. Great stuff!! thanks for the.

    ReplyDelete
  4. Resolved my query.thanks

    ReplyDelete
  5. 1xbet | 1xbet | Bet with a Bonus - RMC | Riders Casino
    1XBet allows you to bet on 1xbet app any febcasino favourite 출장마사지 horse races or any other sporting event. https://septcasino.com/review/merit-casino/kadangpintar Get up to £300 + 200 Free Spins No Deposit

    ReplyDelete
  6. Really Helpful with Proxy.

    ReplyDelete