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.

1 comment:

Your feedback is always appreciated, thanks!!