Deployment in salesforce using ANT

Follow these steps to deploy using ANT
1. Install ANT on you computer.
  In this step download ANT and set up 'folders' on your computer.
   Download apache ant from Here and also download ant set up from salesforce(Folder: apache-ant-1.9.3). For this go to set up --> Develop --> tools --> click on Force.com Migration Tool
ant zipped folder would be downloaded on your computer(Folder: salesforce_ant xx).
 Create new folder "My ANT"(say on dekstop) and paste folder apache-ant-1.9.3 in it. Also, cut files(folder "unpackaged", and both files build files) and paste them in "My ANT" folder.


2. Set up path variable in advanced settings in your computer. For this right click on my computer folder. click properties. click advanced properties --> click advanced tab -->click environment variables button under system variables select path and click on edit. Your path variable will have some parameters just put semicolon after it and then paste the path of bin folder in your apache-ant-1.9.3 after the already existing path variable(put semicolon before the path address ';') i.e your address would look something like this (;C:\Users\username\Desktop\My Ant\apache-ant-1.9.3\bin)
After you have set the correct path click OK so that the change in path variable is saved.

3. Set credentials of the source environment.
   This should be saved in build file of type properties(remember there are two files named build. Credentials should be saved in properties type file)
   Open the file and delete all its content and edit it to save as per following lines
  # my sandbox environment
  sf.serverurl = https://test.salesforce.com
  sf.username = Give your user name
  sf.password = Your security token + password

give your server URL appropriately as shown above, then username and password. remember # infront of a line comments it. While you are retrieving the components make sure all other lines are commented except the above 3 lines of source environment.


4.. Identify the retrieve command from Build(Type: XML) file
  Once you have set the credentials its time to find out command from other build file that will help in retrieving the components.
target name "retrieveUnpackaged"  will be the command used to retrieve the components. You can change this name as per your wish in the build xml file

5. Set the components which you wish to retrieve in package xml document.
   We need to define which are the components to be retrieved and then deployed. This needs to be done in package file present in "unpackaged" folder
   Your default package.xml file will have following

   <?xml version="1.0" encoding="UTF-8"?>
    <Package xmlns="http://soap.sforce.com/2006/04/metadata">  
     <types>        
      <members>*</members>  
      <name>ApexClass</name>  
    </types>
    <types>
       <members>*</members>
        <name>ApexTrigger</name>
    </types>   
 <version>28.0</version>
</Package>
above xml code defines all triggers and all classes. A * between member indicates all members. If you wish to retrieve specific trigger or class than its name shoudl be mentioned.
ex:        <members>mytriggeroncontact</members>
        <name>ApexTrigger</name>
    </types>
   
 this will retrieve mytriggeroncontact trigger. similarly you will have to put which ever components are required to be retrieved.


6. Retrieve the metadata components you wish to deploy.
  We have defined our source environment creds, defined the required components and have identified the command that will retrieve the components.

7. Retrieve components
 press shift key and right click on "my ant" folder, click open command window here. This will open command window and directly take you to ant folder location.
Next will be giving command to retrieve: type ant retrieveUnpackaged and press enter. This will start the retrieving, once done it creates a folder with name "retrieveUnpackaged" this will contain the components to be deployed.
Components contained in this folder will then be used for deployment.


8. Deploy the retrieved components in to destination environment.
   In the build file type in your destination server url, username, and password. Comment the source creds using # or better remove them from the build file.

9. Give deploy command.
 in command window type ant deployUnpackaged. deployUnpackaged is the command for deployment.(you can change the name as per your wish in the build xml file) Command window will show the status of deployment.

2 comments: