Deploy using Force.com Migration Tool

Force.com Migration Tool is Java ANT based command line tool to deploy metadata components from one Salesforce org to another org or deploy same metadata components to multiple Salesforce org's like Developer org -> UAT org -> Pre-Production org -> Production org. It allows you to deploy metadata components likes Objects, Communities, Apex classes, Apex triggers, Lightning Components and Visualforce Pages, and so on. The advantage of using Force.com Migration Tool is, it allows you to schedule a deployment over the weekend or non-business hours. This use Metadata API to deploy the components. It is very useful and time-saving to use Force.com Migration Tool in following scenarios

  • Migrate components from development org to a test org with large amounts of metadata quickly.
  • In the case of multistage release processes using this tool deployment of components can make this activity much more efficient.
  • When IT does deploy from staging org to production org.
  • Deploying metadata components from a local repository to Salesforce org.

Force.com Migration Tool pre-requisite 

Before installing Force.com Migration Tool you need the following to be available and installed on your machine:

  1. Java SE Runtime Environment (v1.7 or higher): To verify that you have properly installed Java, run the following command on Mac Terminal or Windows command line:
          Java –version
    

    Force.com Migration Tool pre-requisite 

    Make sure that the output should look something like the preceding screenshot.

  2. Apache ANT installation (v1.6 or higher): Open the following URL in your browser, then installed ANT version 1.6 or higher http://ant.apache.org/bindownload.cgi. Once you have installed the ANT, the next step is to set the environment variables ANT_HOME and JAVA_HOME. Set ANT_HOME environment variable value to pointing to the directory where you have installed ANT. Set JAVA_HOME environment variable value to pointing to the location of your JDK. On a Mac, it should look like the following screenshot:

    Force.com Migration Tool pre-requisite 

    To verify that you have properly installed and setup environment variables for Ant, run the following command on Mac Terminal or Windows command line:

          ant –version
    

    Force.com Migration Tool pre-requisite 

    Make sure that the output should look something like the preceding screenshot.

Installing Force.com Migration Tool

 Perform the following steps to install Force.com Migration Tool

  1. Open the following URL in your browser, then installed Force.com Migration Tool in your local machine https://gs0.salesforce.com/dwnld/SfdcAnt/salesforce_ant_39.0.zip
  2. Save the ZIP file on your local machine and extract the contents to the directory where you want to store it. It should look something like the following screenshot

    Installing Force.com Migration Tool

  3. Following are the details of folders and files extracted by Force.com Migration Tool
    1. Readme.html contains the instructions how to use Force.com Migration Tool.
    2. Ant-salesforce.jar is a JAR file containing the ANT task.
    3. Sample folder contains the following items:
      1. A codepkg folder contains sample Apex class and Apex trigger.
      2. A mypkg folder contains sample custom object.
      3. A removecodepkg folder that contains XML files for removing the preceding metadata components from your org if deployed.
      4. A sample build.properties file is used to store your Salesforce credentials, to run the task.
      5. A sample build.xml file, that used to deploy and retrieve API calls.
  4. You are now all set to use Force.com Migration Tool.

Creating a project and deploy using Force.com Migration Tool

Force.com Migration Tool allows you to manage version control and keep a backup of your work on your local machine. It also allows you to create folders based on your project or deployment strategy.

A business scenario: David Guzman is working as System Administrator at Universal Containers. In Chapter 7Optimizing Business Processes with Visual Workflow and Approval Processes he has created a custom field on Account object called as Status__c. Now he wants to migrate this field to his personal developer org using Force.com Migration Tool.  

Perform the following steps to deploy metadata components using Force.com Migration Tool

  1. Create few folders in your ANT directory that is  UAT-Metadata and Version 1 inside UAT-Metadata. Then copy build.properties and build.xml files inside UAT-Metadata folder, as shown in the following screenshot:

    Creating a project and deploy using Force.com Migration Tool

  2. The next step is to edit build.properties file and enter Salesforce credentials for source org to retrieve the metadata components based on the schema defined inside the package.xml (we will create package.xml in next step):

    Creating a project and deploy using Force.com Migration Tool

  3. The next step is to build a package.xml file that contains account's custom field Status__c. Either you can create it manually with the help of Metadata API developers guide or use Force.com IDE to do so. Once you have the package.xml file moves it to inside the Version 1 folder. Then it should look something like the following screenshot:

    Creating a project and deploy using Force.com Migration Tool

    Your package.xml should look like the following screenshot:

    Creating a project and deploy using Force.com Migration Tool

  4. Then edit the build.xml file and set the package.xml location, inside target retrieveUnpackaged tag, as shown in the following screenshot:

    Creating a project and deploy using Force.com Migration Tool

  5. Open the Terminal on Mac and navigate to the directory of the UAT-metadata for the current scenario. Then run the following command on Mac Terminal or Windows command line to retrieve the metadata components from source org for schema defined inside package.xml:
          ant “retrieveUnpackaged”  
    

    Creating a project and deploy using Force.com Migration Tool

    If the retrieval or build is successful, then you will get success message on the screen. It should look like something the preceding screenshot. The next step is to navigate to UAT-Metadata folder on your local machine. After successful retrieval of metadata components from source org, it should contain a folder object inside retrieveUnpackaged folder, as shown in the following screenshot:

    Creating a project and deploy using Force.com Migration Tool

    Inside object folder, you can find the document Account.Object that contains complete schema of account's custom field Status__c:

    Creating a project and deploy using Force.com Migration Tool

  6. To deploy metadata components to target org, navigate to UAT-Metadata folder on your local machine and edit the build.properties file to change the Salesforce credentials pointing to target org.
  7. Open the Terminal on Mac and make sure that you are still inside UAT-Metadata folder. Then run the following command on Mac Terminal or Windows command line to deploy metadata components to target Salesforce org ant “deployUnpackaged”:

    Creating a project and deploy using Force.com Migration Tool

    If the deployment is successful, then you will get success message on the screen. It should look like something the preceding screenshot.

  8. The final step is to login into your target org and verifies the deployment.

Design the folder structure as your want. Make sure to update the folder structure in build.xml file.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.16.229