Migration tool to deploy meta data between Organizations
Migration tool is used to deploy the Metadata from one organization to other organization. By using this tool first we will get the code to our local from source organization and we will deploy from local to target instance. It is very easy process to deploy the large number of components from source to target instance.
Force.com migration tool is a java/Ant based command line utility for moving the Meta data between local directory and a Salesforce organization. The Force.com Migration Tool is especially useful in the following scenarios:
1. Development projects where you need to populate a test environment with large amounts of setup changes — making these changes using a Web interface could take a long time.
2. Multistage release processes — a typical development process requires iterative building, testing, and staging before releasing to a production environment. Scripted retrieval and deployment of components can make this process much more efficient.
3. Repetitive deployment using the same parameters — you can retrieve all the metadata in your organization, make changes, and deploy a subset of components. If you need to repeat this process, it’s as simple as calling the same deployment target again.
4. When migrating from stage to production is done by IT — anyone that prefers deploying in a scripting environment will find the Force.com Migration Tool a familiar process.
Installing Force.com migration tool
1. Install Java on your local machine
Go to http://www.oracle.com/technetwork/java/javase/downloads/index.html. And get the latest version of the Java JDK and install it on your machine.
2. Install ANT in your local machine.
Go to http://ant.apache.org/bindownload.cgi and get these files to your local. Once these files are on your computer, there is no further installation required.
3. After installation of java and ANT, create following environment variable to set the path.
|ANT_HOME||Here give Ant location on your machine. For example in my machine I have stored ant in “C:\Ant\apache-ant-1.8.4” location|
If you are working under proxy network you need to create one more additional environmental variable to specify proxy settings.
4. Download Salesforce.jar file and add that file to your ant installation’s lib directory.
To download this Go to setup->Develop-> click on Tools -> and click on Force.com migration tool to download this. Refer following screen.
After downloading extract the downloaded ZIP file and copy the ant-salesforce.jar file and paste it in Ant lib directory in your ant installation file.
5. Now Force.com migration tool installation is completed.
To verify java installation open command prompt ant type “Java –version” you will get the following message based on the java version.
java version “1.6.0_37”
Java(TM) SE Runtime Environment (build 1.6.0_37-b06)
Java HotSpot(TM) Client VM (build 20.12-b01, mixed mode, sharing)
To verify ANT installation type ant –version in command prompt, you will get following message based on the ANT version.
Apache Ant(TM) version 1.9.1 compiled on May 15 2013
How to use Migration tool to deploy components in Salesforce?
To deploy metadata by using this migration tool we need prepare below mentioned three important files.
1. Build.properties file: This file contains your organization’s credentials in order to run the tasks in build.xml file.
Parameters used in build.properties file
|username||Here you need to mention your organization user name like below users.For example firstname.lastname@example.org in production, email@example.com in sandboxThis users must have “modify all data” permission to deploy components.|
|password||You have to specify your password along with security token(Password + Security token)|
|serverurl||For production it is https://login.salesforce.comFor sandbox it is https://test.salesforce.com|
2. Build.xml file: This file specifies a series of commands to be executed by Ant. Within the build.xml file are named targets that process a series of commands when you run Ant with a target name. below image describes sample build.xml
3. Package.xml: This file is a project manifest that lists all the components you want to retrieve or deploy in a single request. You can retrieve or deploy only a single package at a time. Below image describes sample package.xml file
You can get these sample(build.xml and build.properties) files from migration tool zip file downloaded earlier as part of installation.
After creating these three files Place these files in a folder, place package.xml file in separate folder inside this folder, see the following image for reference.
Place the package.xml file in codepkg folder.
Once you have done with this setup, you can run this script in Command prompt.
How to run this script in command prompt
1. Open command prompt and enter file path of your build.xml file.
For example I have placed my build.xml file in “C:\Build”. Enter this command in command prompt “cd C:\Build”.
2. Now retrieve the code your local from source organization. To retrieve the components mentioned in your package.xml run the command “ant retrieveCode” which is mentioned in your build.xml
3. Once you have done with retrieving components to your local, now you can deploy those components to your target organization. To deploy your components run the command “ant deployCode”, which is mentioned in your build.xml file.
If your deployment is success, you will get successful message. In case of failure you will get the list of errors.