Sunday, December 18, 2011

Migrating Documents using Force.com Migration Tool/ANT


Had a hell of a time in migrating Document folders from a Sandbox to production using ANT. Didn't want use the force.com IDE for this as it hangs a lot, so I decided to use Force.com Migration Tool/ANT

Writing this post to explain the right process that I explored while migrating the document folders. Its not explained in the salesforce docs properly, so it took me 6 hours to figure it out myself and deploy the folders after already spending 5 hours in retrieving them. What I found surprizing was that I didn't get my answers to my questions from Google :( (sad, but no dis-respect to Google)

I have already described the installation in the previous post, so will not describe here.

Here are the complete set of steps:

1. So, first of all you need to retrieve the names of folders by using the listMetadata command specifying the folder names.

Take the sf.metadataType in build.properties file as "Document". The script in build.xml will look like:

<target name="listMetadata">
      <sf:listMetadata
            sessionid="${sf.sessionid}"
            serverurl="${sf.serverurl}"
            metadataType="${sf.metadataType}"
            folder="<folder name>"
            resultFilePath="list.log"/>
</target>

running above script will list all the files in list.log file in the same folder as build.xml.

2. Open package.xml from Unpackaged folder and list all the file names within <members> tags, it will look like:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members><Folder name1></members>
        <members><Folder name1/File name1></members>
        <members><Folder name1/File name1></members>

        <members><Folder name2></members>
        <members><Folder name2/File name2></members>
        <members><Folder name2/File name2></members>

        <name>Document</name>
    </types>
    <version>23.0</version>
</Package>

3. Run command, retrieveUnpackaged to retrieve the folders and file in them in retrieveUnpackaged/documents directory.

4. Change the username and password for the destination org in build.properties file.

5. Run command, deployUnpackaged to deploy the folders in the destination org.

NOTE: The key point is you need to extract the folder as <members><Folder name1></members> and the files within them as <members><Folder name1/File name1></members>. The folders also get extracted with a metadata and deployed too.

Friday, December 9, 2011

Getting started with Force.com Migration Tool for deployments

Pre-requisites:
  1. Apache ANT in the CLASSPATH
  2. JDK
  3. Force.com Migration tool
 Installation of ANT becomes a little tricky especially for the beginners, so here are the steps along with the screenshots.
  1. Download the latest release of Apache ANT in .zip format from Apache’s web site: http://ant.apache.org/bindownload.cgi
  2. Unzip to an appropriate folder.
  3. Install JRE, if you don’t have it already.
  4. Download force.com migration tool your salesforce org by going to Setup > Develop > Tools
  5. Unzip force.com migration tool and copy ant-salesforce.jar to the lib directory of your ANT folder created in step2.
 Now, to set the classpath for ANT installation, follow the steps below:
  1. Go to My Computer > Properties > Advanced tab > Environment Variables
  2. Create a new variable in user variables with name ANT_HOME and value as <Complete path of your ANT installation>. For eg: if your ANT installation path is D:\Downloads\apache-ant-1.8.1
    • ANT_HOME
    • Note: Don’t leave a space and don’t put a backslash at the end of the path.
    •  
  3. Create another variable JAVA_HOME and put the full path of the JDK installation in the same way as step2.
    JAVA_HOME
                                                                                           
  4. Create a third variable by the name PATH and put the value as %ANT_HOME%\bin;%JAVA_HOME%\bin