部署做好的metafile到服务器有两种常用的方式, 利用IDE部署到服务器-> deploy to server 还有就是利用ant进行部署,下面记录一下,利用ant进行部署的几个关键点 准备工作:
- ANT(1.6以上) + J2SE(1.5以上) ←ant运行环境
- SFDC关联的部署插件 这个需要login到SFDC的环境里面,在设定-〉开发-〉tool里面下载
- 把2种下载的文件,解压,把ant-salesforce.jar文件copy到ant的lib下面
- 编写build.xml文件
文件结构 ant/bin/ant
build.xml
build.properties
src/package.xml
class/*****
objects/******
- 下面是一个例子
# build.properties # # Specify the login credentials for the desired Salesforce organization sf.username = xxxxxxxxx sf.password = xxxxx #sf.pkgName = <Insert comma separated package names to be retrieved> #sf.zipFile = <Insert path of the zipfile to be retrieved> #sf.metadataType = <Insert metadata type name for which listMetadata or bulkRetrieve operations are to be performed> # Use 'https://login.salesforce.com' for production or developer edition (the default if not specified). # Use 'https://test.salesforce.com for sandbox. sf.serverurl = https://test.salesforce.com # If your network requires an HTTP proxy, see http://ant.apache.org/manual/proxy.html for configuration. #
build.xml <project name="Sample usage of Salesforce Ant tasks" default="test" basedir="." xmlns:sf="antlib:com.salesforce"> <property file="build.properties"/> <property environment="env"/> <!-- Deploy the unpackaged set of metadata retrieved with retrieveUnpackaged --> <target name="deployUnpackaged"> <sf:deploy username="${sf.username}" password="${sf.password}" serverurl="${sf.serverurl}" deployRoot="src"/> </target> <!-- Shows check only; never actually saves to the server --> <target name="deployCodeCheckOnly"> <sf:deploy username="${sf.username}" password="${sf.password}" serverurl="${sf.serverurl}" deployRoot="src" checkOnly="true"/> </target> </project>
准备要部署的metafile文件和package.xml 编写package.xml 把这次要部署的文件列表写入到package.xml 例子: <?xml version="1.0" encoding="UTF-8"?> <Package xmlns="http://soap.sforce.com/2006/04/metadata"> <types> <members>xxx1</members> <members>xxx2</members> <name>ApexClass</name> </types> <types> <members>xxx1</members> <members>xxx2</members> <name>ApexPage</name> </types> <types> <members>xxx1</members> <members>xxx2</members> <name>ApexTrigger</name> </types> <types> <members>xxx1</members> <members>xxx2</members> <name>CustomApplication</name> </types> <types> <members>xxx1</members> <members>xxx2</members> <name>CustomLabels</name> </types> <types> <members>xxx1</members> <members>xxx2</members> <name>CustomObject</name> </types> <types> <members>xxx1</members> <members>xxx2</members> <name>CustomObjectTranslation</name> </types> <types> <members>xxx1</members> <members>xxx2</members> <name>Layout</name> </types> <types> <members>xxx1</members> <members>xxx2</members> <name>ReportType</name> </types> <types> <members>xxx1</members> <members>xxx2</members> <name>Profile</name> </types> <types> <members>xxx1</members> <members>xxx2</members> <name>StaticResource</name> </types> <types> <members>xxx1</members> <members>xxx2</members> <name>Translations</name> </types> <types> <members>xxx1</members> <members>xxx2</members> <name>Workflow</name> </types> <version>23.0</version> </Package>
进行部署检证
ant deployCodeCheckOnly
进行实际部署
ant deployUnpackaged