Hello everyone, It's been a long time since I published my last
post. But this time I came up with very interesting topic,Migration. We all know
that migration in salesforce is not that much easy. But if we have proper
knowledge about it then it wont cause any problem at any level. Then lets get started.
What is Migration?
Traditional definition of migration is "seasonal movement of
animals from one region to another." The same definition is applied for
salesforce too.
In salesforce instead of animals there will be the development or
customization which would be done by developer or admin. And instead of moving
from one region to another region, We have to move it from one org to another.
See!! Migration is the same in real life as well as in salesforce.
Now, let's see what are the ways to do migration in salesforce.
1) Using Eclipse
2) Using Change-sets
3) Using Force.com Migration tool
I'll explain each and every technique one by one.
1) Using Eclipse
Eclipse is an integrated development environment(IDE). It contains
a base workspace and an extensible plug-in system for customizing the
environment. Written mostly in Java,Eclipse can be used to develop
applications.
Eclipse is also providing force.com plugins, You must have to
install that plugins in order to perform migration.
After installing force.com plugins, you have to create new project
in force.com and export the whole org.
Now you'll see all the metadata are exported in eclipse at left
side outline. From that list of metadata you can choose the component that
you've to migrate. That component could be anything like class, pages, field
update, workflow rules etc.
I'll give you example of migrating object from one org to another.
Then you can migrate any component using this technique.
Here I've created one object named Object A in my personal org and
trying to move another org. I've already exported my personal org in eclipse.
- Now right click on that, choose Force.com then click on
deploy to server. Following is the snippet of that.
Now, You'll see the following screen and put the username and
password of the destination org where you want to migrate everything. For
ignoring to add security token, you also have to add ip address into that
destination org.
After adding username and password, click on next. You'll see now
the following screen. In that you've to add Directory then click next.
You can see following screen which will show the component that
you're migrating. You can also validate that component on clicking validate
Deployment button. Then click Next.
If you see the following message then congratulation, You've
successfully migrated one object from one org to another org.
Click Finish. And you're done.
You can migrate everything using the below process.
2) Using Change-sets
Migration using change sets only works if you are migrating from sandbox to production. Migration using change sets is the easiest way to do migration.
For migrating using change set from sandbox to production, You've to logged in to sandbox first then go to setup >> outbound change set.
Add name to that outbound change set and add description just to understand that what are you migrating.
Then you'll be asked to add components from available components. You can add anything from available components.
There is one thing that you have to take care if you're migrating classes using change sets then each and every class must have their test class also included into change set. All over code coverage must be more than 75%.
Once you've added all the components in outbound change sets then upload it. It'll be uploaded to production.
Now login to production. Go to setup >> Inbound change sets, There you'll be able to see the same change set which you've uploaded into sandbox. click on that change set.
Now you can see two buttons, one is Validate and second is Deploy, It's always best practice to validate your change set before deploying. So if there would be any error then you'll be informed before deploying,
After you've validated your change set successfully then you can deploy it to production.
I'm very sorry that I am not able to show you guys snippets/screenshots for this because it require sandbox and production org. Change sets are not available in developer org. But I hope this will help you. And If you guys face any problem in this topic then feel free to write your comment below.
3) Using Force.com Migration tool
Migration using force.com migration tool is little difficult but it'll make your task so much easy if you want to do continuous integration. Continuous integration in the sense that you'll be given a fresh set of orgs and you have to migrate same thing in each and every org. Then this tool is very helpful.
When I came to know about this migration tool, I had a question by myself that why do we need this tool if we can migrate everything using eclipse but then I know, eclipse is more user friendly, but for continuous integration it's not best option.
We can schedule migration in force.com migration tool. Force.com migration tool is nothing but the ANT tool which is java based migration tool for salesforce. Let's get started then how to use ANT tool for migration.
Prerequisites : - JDK 1.5 or above
- ANT version 1.6 or above
For checking that JDK is installed in your system or not, you have to check in command prompt. Click Start, write cmd and open it.
Write "Java -version" in command prompt. if it shows the o/p like following then java is installed in your system.
If you do not get the given o/p then JAVA is not installed in your system. For installing java, please go to following link.
Now for checking that Is ANT installed in your system or not, Follow the same steps to the command prompt, but instead of writing "Java - version" you've to write "Ant -version." And check that your o/p matched with the following screenshot or not.
If your o/p doesn't match with the given o/p then please download the ANT from following link.
Now unzip the file which you've downloaded and set Environment variable. I would prefer that you should set it in the existing environment variable where you set the java environment variable. The path should be parent folder of "bin",Also add the "bin" folder to your path. Let me show you the snippet of setting variable.
Now copy that address and paste it just after the path in environment variable where you've set the java path. Like following.
" C:\Program Files (x86)\Java\jdk1.6.0_22\bin;C:\ANT\apache-ant-1.9.4\bin\;"
Now you've successfully installed the Ant in your system.After performing this, check again in command prompt that does ANT tool is installed in your system or not.
Now we can start the original process, Migration using force.com migration tool. There are two terms that you've to keep in mind for doing migration using this tool. One is source org, and second is destination org.
Source org is the org from where we want to migrate everything, while destination org is the org at where you have to migrate everything.
In terms of starting migration, you've to install force.com migration tool from your org. For that go to setup >> tools. There you'll see "Force.com Migration tool".
Zip file will be downloaded once you clicked on that force.com migration tool. Unzip that file and you'll see it contains three items. one folder and two files. which are Sample(Folder), Readme(File) and ant-salesforce(File).
Now you've to copy ant-salesforce file and paste it into lib folder of ANT (where the ant is installed).
Go to Sample folder >> unpackaged. There you will see file named package. Another concept came here which is XML. This file is nothing but the package.xml. In that you've to add each and every component manually. Which I'm going to explain how.
Given below code is nothing but the package.xml file when you open it for the first time. You can see that there are only two types mentioned in this code, Apex class and Apex triggers.
In the <name> tag, we've to specify which component do we need to add.
While in <member> tag we've to specify the api name of that of component which we specified in <name> tag.
Let me give you example here, I created one class, page, object and trigger in my personal org. I'll show you how to migrate that from one org to another. For that we need to add that components in package.xml. Following are the components API name in my personal org.
Class name : Accounthandler
Page name : ExceptionPage
Object name : Test_Object__c
Trigger name : AccountTrigger
Save this file, One part is over, Now you have to go to sample >> build.properties file. you can see sf.username and sf.password, there you've to set your source org username and password. Add sf.serverurl as per your requirement, if it's developer or production then choose login.salesforce.com else if it's sandbox then choose test.salesfoce.com. Now save it.
Open command prompt, go to the directory where you extracted the force.com migration tool. Like I've installed it in drive D >> Deployment >> test. So my command prompt would be like given below. Write "ant retrieveUnpackaged" command there. Once the components will be retrieved it'll automatically create one folder named "retrieveUnpackaged".
Once we'll run the command. It'll show the status. See the following snippet.
Now we've successfully retrieved all the components from the source org which we added in package.xml file. You can cross check it in "retrieveUnpackaged" folder. As you can see in my "retrieveUnpackaged" folder which is given below.
Now you've everything in your system which you want to migrate. Again go to build.properties file and remove your source org credentials and add the destination org credentials, Don't forget to add sf.serverurl of destination org.
Now follow the same process which you've performed in retrieving data. Again open command prompt and go to sample directory. and write "ant deployUnpackaged" command and press enter.
Congratulation, You've finished your first migration using ANT/Force.com migration tool.
Notes :-
- If you're facing any problem while retrieving or deploying components then you've to set your ip address according to your source org or destination org. Like if you're facing issue while retrieving then set ip address in source org and if you're facing issue while deploying then set ip address in destination org.
- For continuous integration, ANT tool is the best tool. You just have to prepare your package.xml file. I'll give you example of package.xml file which contain almost each and every component. So it'll help you to create your own package.xml file.
Following is the example of package.xml file which contains almost each and every component of one ordinary org. You can prefer this file for creating your own package.xml file.
The example which I gave you shows only few components but ANT is much more than that, We can schedule our migration even we don't have to look out for any dependencies if they're mentioned package.xml file.
Finally You've reached to the end of this topic. I know this topic is a bit lengthy but worth to read it. I hope this will help you guys, Next time I'll come up with more interesting and helpful topic. If you've any doubts then you can ask me in comments. Kudos. :)