The Force.com Migration Tool is a Java/Ant-based command-line utility for moving metadata between a local directory and a Salesforce organization. The migration tool is useful for migrating large scale or repetitive changes between environments.
Prerequisites for using Force.com Migration Tool:
Before using Force.com Migration Tool, Java and Ant must be installed correctly.
Installing Java: In a Web browser, navigate to http://java.sun.com/javase/downloads/index.jsp and install the latest version of the Java JDK.
Verify Java Installation: To see if we have Java installed: In the command prompt, type java -version and press Enter. The output should look something like the following:
java version "1.5.0_01" Java(TM) SE Runtime Environment (build 1.5.0_01-b06) Java HotSpot(TM) Client VM (build 1.5.0_01-b06, mixed mode)
Ant Installation: Download Apache Ant .http://ant.apache.org/bindownload.cgi. This directory will be known as ANT_HOME. Add the bin directory to your path. (Only the bin and lib directories are required to run Ant.) If we are using a Windows operation system, create an ANT_HOME environment variable and set the value to where we have installed Ant. Also create a JAVA_HOME environment variable and set the value to the location of your JDK.
Verify Ant Installation
Installing the Force.com Migration Tool:
To download and install the Force.com Migration Tool:
Create the following two environment variables if they are not existing.
GeneralSteps The general procedure we will follow when using the Force.com Migration Tool to copy metadata from one Salesforce organization to another is:
Inclined to build a profession as SalesForce Developer? Then here is the blog post on, explore SalesForce Training
To fetch the data from the source environment Create a folder say some “Migration folder” and create the following in it.
Build.properties file should look like this Give user id, password, server URL like below username = user@gehc.amer.sprintdev
password = password12jSZQVS7erefdUMfjcoFSgr7Mqx server URL = https://test.salesforce.com
Build.xml file should have the following
<!--Retrieve the contents from the source environment-->
<target name="retrieve"> <mkdir dir="retrieveMetadata"/> <setproxy proxyport="80" proxyHost = your proxy proxyuser = 'username' proxypassword = 'password' /> <sf:retrieve username="${sf.username}" password="${sf.password}" serverurl="${sf.serverurl}" retrieveTarget="retrieveMetadata" unpackaged="retrieveSource/package.xml" pollWaitMillis="10000" maxPoll="100"/> </target>
<!-- Deploy the changes into destination environment -->
<target name="deploy"> <setproxy proxyport="80" proxyHost = your proxy proxyuser = 'username' proxypassword = 'password' /> <sf:deploy username="${sf.username}" password="${sf.password}" serverurl="${sf.serverurl}" deployRoot="retrieveMetadata" /> </target>
<!-- Delete the changes made to the description environment-->
<target name="remove"> <setproxy proxyport="80" proxyHost = your proxy proxyuser = 'username' proxypassword = 'password' /> <sf:deploy username="${sf.username}" password="${sf.password}" serverurl="${sf.serverurl}" deployRoot="remove" /> </target>
Finally, the build.xml file should look like below.
3)Package.xml file should contain all the metadata information like objects, classes, triggers etc that needs to be migrated or retrieved. In the source environment, just create a new field or class or trigger to verify the migration is successfully taken place in the destination environment. In the below example, the following are created in the source environment
Keep all the data that needs to be retrieved from source environment in <types> like this.
<types> <members>Account.MigrationTest_Field__c</members> <name>CustomField</name> </types> To retrieve all the triggers or classes, put *. Like this <types> <members>*</members> <name>ApexTrigger</name> </types>
Finally, the package.xml file should look like this
We need to go to the command prompt and type the commands to do the following
Go to folder directory in the command prompt where the “Migration folder” is created. Type the following command Type the command[ +$to fetch the data from the source environment into the folder. After executing the above command, the below details are visible in the command prompt.
Go to the source folder and verify whether all the data mentioned in the package.xml is fetched from the source environment. We will find a folder called retrieve Metadata that contains all the retrieved data from the source environment. Now, give the credentials of the destination environment in the build.properties file. And type the following command. Deploying Data
Type “Ant deploy” in the command prompt Now after the files are deployed, we will get the following info in the command prompt.
Now go to the UI and check whether all the files are migrated to the destination environment. With this example, we can see all the above-provided data will be migrated and available in the destination environment.
Integrating with Subversion
Using the Subclipse IDE we can log in to SVN repository and checkout the branch which we have latest code and metadata into a local directory. As mentioned in the Fetching data section we can run deploy command to deploy the contents which are mentioned in the package.xml will get deployed to the destination environment.
You liked the article?
Like: 0
Vote for difficulty
Current difficulty (Avg): Medium
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.