Sunday 18 May 2014

Salesforce Deployment Methods

Salesforce Deployment Methods
There are three ways of deployment to Salesforce:
1)      Deployment Changeset, Disadvantage-> can only be deployed to sandbox or connected org.
2)      Force.com Eclipse IDE
3)      Force.com Java based ANT Scripts
In this blog post we are going to learn about retrieving salesforce components through ANT. To use ANT one should have:
1)      Java installed in local machine
2)      Apache ANT installed into local machine
3)      Ant-Salesofrce.jar file from Salesforce (which is to be copied into Home_Folder>ant>lib).
ANT Setup
  1.   Download ANT from http://ant.apache.org/bindownload.cgi
  2.   Extract the folder and paste it into Home_Folder.
  3.   Also Download the ant-salesforce.jar from salesforce org. To download follow the steps Setup>Develop>Tools. Click Force.com Migration Tool and paste the .jar file into Home_Folder>ant>lib.
  4.  Setup the Environment variable from My Computer>Rightclick-Properties>Advanced Syatem setting>Click Environment variable. Add new System variable, Enter name as ‘ANT_HOME’ and location as drive location of bin folder for ant. Also check whether Java classpath is set in system variable.
  5.  Optional, we can check whether ant and java is installed by using commands ‘ant –version’ and ‘java –version’.

  1. Building ANT package.xml, Build.xml and Build.properties
Build.properties file(please change the username and password in below file)
 1. # build.properties  
 2. #  
 3.    
 4. # Specify the login credentials for the desired Salesforce organization  
 5. sf.username = DemoUsername  
 6. sf.password = Password  
 7. #sf.pkgName = <Insert comma separated package names to be retrieved>  
 8. #sf.zipFile = <Insert path of the zipfile to be retrieved>  
 9. #sf.metadataType = <Insert metadata type name for which listMetadata or bulkRetrieve operations are to be performed>  
 10.   
 11. # Use 'https://login.salesforce.com' for production or developer edition (the default if not specified).  
 12. # Use 'https://test.salesforce.com for sandbox.  
 13. sf.serverurl = https://login.salesforce.com  
 14.   
 15. sf.maxPoll = 20  
 16. # If your network requires an HTTP proxy, see http://ant.apache.org/manual/proxy.html for configuration.  
 17. #  

Build.xml
 <project xmlns:sf="antlib:com.salesforce" basedir="." default="test" name="org to org">  
 2.   <property file="build.properties" />  
 3.   <property environment="env" />  
 4.      
 5.   <target name="retrieve_dev" depends="">  
 6.     <echo message="retrieving metadata to ${metadata.root}" />  
 7.         <mkdir dir="retrieveOutput"/>  
 8.     <sf:retrieve retrieveTarget="retrieveOutput" singlePackage="true" serverurl="${sf.serverurl}" password="${sf.password}"username="${sf.username}" unpackaged="MyPkg/package.xml"/>  
 9.   </target>  
 10. </project>  

Package.xml
 <?xml version="1.0" encoding="UTF-8"?>  
 2. <Package xmlns="http://soap.sforce.com/2006/04/metadata">  
 3.   <types>  
 4.     <members>*</members>  
 5.     <name>ApexClass</name>  
 6.   </types>  
 7.     
 8.     
 9.   <version>29.0</version>  
 10. </Package>  

Deployment Commands
Type ‘ant TARGET_NAME’ where TARGET_NAME=name attribute of target tag in Build.xml(in this case retrieve_dev. The Build process will start after creating a folder named ‘retrieveOutput’ under which the required salesforce components will be saved in file system(Please ensure that the current folder location in which ’ retrieveOutput’ is created, must have sufficient admin rights for creating and editing file contents .

Deployment through Eclipse:
ANT is by dedault the part of Eclipse IDE just we need to add the ant-salesforce.jar from salesforce org. Follow the below steps:

  1.  Open Eclipse, then go to Windows>Preferences.
  2.  Select ANT>Runtime and choose Ant Home Entries(Default)

  3.  Click Add JAR and choose the ant-salesforce.jar, then click apply.
  4. Save the setting by clicking Ok.
  5. Now Create a new project in Eclipse and import the build.properties and build.xml
  6.  Right click build.xml in your project>Run as>Build ant.
  7.  Select the configuration target from list which performs the desired action
  8.    Optionally we can setup the arguments for build.properties separately(by clicking Main tab in above fig) for e.g : -Dsf.srcdir="DIR _SRC_ PATH "
  9.  Finally click Run and observe the Eclipse console for logs.
  10. After the complete process we’ll get the message as Build Succeeded (or Build Failed).






No comments:

Post a Comment