Following are the three ways to Migrate code, objects, schema etc… from organization to another :
- Change sets (From Salesforce site)
- Eclipse (Using “Deploy to force.com server” option in Eclipse)
- ANT (Java based tool)
We are going to discuss the ANT based migration, step by step:
Prerequisite:
JDK 1.5 or above
Step 2:
Set Environment variable “ANT_HOME”. The path should be of parent folder of “bin”. Also add the “bin” folder to your path.
Step 3:
Check whether ANT is installed or not properly by running command “ant -version”. It might be possible that you receive message something like “unable to find tools.jar”. You can copy this jar from “JDK_HOME/lib/tools.jar” to “JRE/lib” folder.
Salesforce Get ANT version
In above screen you can see that before copying “tools.jar” I was getting warning.
Step 4:
Login to salesforce and navigate to “Your Name |Setup | Develop | Tools” and download“Force.com Migration tool”.
Unzip the downloaded file to the directory of your choice. Copy the “ant-salesforce.jar” file from the unzipped file into the ant lib directory.
To start with deployment using ANT, we will need “build.xml” and “build.properties” file. As there is no need of “build.properties” however its good to have it so that the configuration related settings are in different file. You can copy both files from “sample” folder of unzipped content from salesforce. Following is the structure of “build.properties” file.
3 | sf.username = <SFDCUserName> |
4 | sf.password = <SFDCPasswrd><SecurityToken> |
10 | sf.serverurl = https:// test .salesforce.com |
Step 5:
Copy all folders with source code from source organization using eclipse. Lets say the root folder name is “test1”.
Create “build.properties” from above code snippet or copy it from unzipped folder. Now create “build.xml” needed by ANT. Following is the example of build.xml file:
1 | < project name = "Shivasoft ANT Tutorial" default = "deployCode" basedir = "." xmlns:sf = "antlib:com.salesforce" > |
2 | < property file = "build.properties" /> |
3 | < property environment = "env" /> |
5 | < target name = "deployCode" depends = "proxy" > |
6 | < sf:deploy username = "${sf.username}" password = "${sf.password}"
serverurl = "${sf.serverurl}" deployRoot = "test1" > |
7 | < runTest >TestClassName</ runTest > |
11 | < target name = "undeployCode" > |
12 | < sf:deploy username = "${sf.username}" password = "${sf.password}"
serverurl = "${sf.serverurl}" deployRoot = "removecodepkg" /> |
15 | < property name = "proxy.host" value = " ProxyURL " /> |
16 | < property name = "proxy.port" value = "1234" /> |
17 | < property name = "proxy.user" value = "UserName" /> |
18 | < property name = "proxy.pwd" value = "Password" /> |
19 | < setproxy proxyhost = "${proxy.host}" proxyport = "${proxy.port}"
proxyuser = "${proxy.user}" proxypassword = "${proxy.pwd}" /> |
Attribute “deployRoot” means the root folder from which the code should be copied and tag<runTest> means the testclasses which should run after the deployment. At last, go to the folder “test1” from command line and run command “ant deployCode”.
Salesforce Migration using-ANT
Checking the status of the task:
To know the status of task you can run command:
Ant targetName -Dsf.asyncRequestId=requestID
Using Proxy in ANT migration tool:
If your organization uses the proxy then add below target in “build.xml” and specify this target as dependent.
2 | < property name = "proxy.host" value = " ProxyURL " /> |
3 | < property name = "proxy.port" value = "1234" /> |
4 | < property name = "proxy.user" value = "UserName" /> |
5 | < property name = "proxy.pwd" value = "Password" /> |
6 | < setproxy proxyhost = "${proxy.host}" proxyport = "${proxy.port}"
proxyuser = "${proxy.user}" proxypassword = "${proxy.pwd}" /> |
Retrieve content from Salesforce Organization:
create “package.xml” for the list of component to be retrieved and add following task in “build.xml”.
3 | < target name = "test" depends = "proxy" > |
4 | < mkdir dir = "retrieveUnpackaged" /> |
6 | < sf:retrieve username = "${sf.username}" password = "${sf.password}"
serverurl = "${sf.serverurl}" retrieveTarget = "retrieveUnpackaged"
unpackaged = "unpackaged/package.xml" unzip = "false" /> |
“Unzip” attribute specifies that the code retrieved should be in Zip format or not. By default the value is true means it will not in zip format.
Ref:
Comments