Thursday 9 April 2015

Faster and Efficient Salesforce Deployment Steps Using the ANT Migration Tool

Salesforce Deployment ???  : )

       Most of you know, there are various deployment tools available such as Change Set, Force.com IDE or Eclipse and ANT Migration Tool. This tutorial will be helpful to know how to use and deploy code in salesforce using ANT Migration tool.

Force.com Migration Tool

      The Force.com Migration Tool is a Java/Ant-based command-line utility, based on the Force.com Metadata API, for moving metadata between a local system directory and a Force.com organization.It's simple, faster and efficient deployment tool.  You can also learn more about ANT tool usage on Force.com Migration Tool Guide

ANT Environment Setup

        Please take care of the below installation steps. Skip the below steps if you already configured JAVA and ANT.

       1. Java 
               Download Java
               Setup Path

       2. ANT Tool
               Download ANT
               Installation Instructions

ANT Deployment Folder Structure

      1. Create a folder on any of your hard disk partition. For example, i have created folder called "Build" in "D:" colon. 
      2. Download this XML file Download Link
      3. After download, Paste the download XML file into the Folder that you created. For me i pasted this file into Build Folder.
    
Creation of Outbound Change Set
 
Change Set available only on Sandbox Org. 

    1. From Setup, click Deploy | Outbound Change Sets.
    2. Click the name of a change set.
    3. Select the organization you want to send the change set to.
    4. You don't need to upload it.


Consider i have created change set named DeploymentChangeSet

      1. Go to the Folder Build, then Edit the build.xml file in your editor app. Such as Notepad++, notepad, etc. My preference go with Notepad++.

      2. In Line No: 8, you will find the below code


  1.     <property name="create.folder" value="Your Folder Name" />

Enter the Folder name in the place of value.

    3. In Line No: 11, you will find the below code,


  1.     <property name="my.pkgName" value="Your Change Set Name" />

Enter the Change Set name in the place of value attribute. For me, i created change set called DeploymentChangeSet


    4. From Line No 17 to 20, you will find the below code,


  1.     <target name="retrieveCode">
  2.         <mkdir dir="${create.folder}"/>
  3.         <sf:retrieve username="Source Org Username" password="Password With Security Token" serverurl="https://test.salesforce.com"retrieveTarget="${create.folder}"packageNames="${my.pkgName}"/>
  4.     </target>

Enter the source org username in the place of username attribute, the give the source org password with security in the place of password attribute. serverUrl refers the your org url, for me source org is sandbox, hence the URL will be test.

   5. From Line No 23 - 26, you will find the below code,


  1.     <target name="deployCode">
  2.         <sf:deploy username="Target Org Username" password="Password With Security Token" serverurl="https://test.salesforce.com"deployRoot="Your Folder Name" >
  3.         </sf:deploy>
  4.     </target>

Enter the target org username in the place of username attribute, the give the target org password with security token in the place of password attribute. serverUrl refers the your org url, for me target org is sandbox, hence the URL will be test. change this according to your org.

   6. Save the build.xml. If overwrite/replace option asked means, then please do that.

ANT Deployment Steps

  1. Run the Command Prompt.

  2. Go the your folder name, for example i have created folder in D: and folder name is Build.

  3. Type ANT -verbose retrieveCode





  4. Your components will be retrieve from the change set and it will be stored in the Build directory.

  5.  Type ANT -verbose deployCode




For Developer edition, you cannot create ChangeSet. So you can just take a backup from eclipse. Then Paste the deployment components in the folder structure, such as classes, objects, etc. In this scenario, you can just mention the target org in build.xml and and directly you can deploy it to any org.

You will see the deployment status in CMD, also you can check it in Deployment Process under Setup up in the target org.

That's it...!

Comment your doubts if you are not clear...!

1 comment:

Activities: Assign Tasks to a Queue Salesforce Lightning

Salesforce announced to assign Tasks to a Queue beginning from Spring'20 release. How does it work? In Setup, enter Queues in th...