Many post about deployment using ANT has been posted on this blog like auto backup complete Salesforce instance daily, upload Salesforce data on FTP Server, auto generate package.xml, continuous integration and so on.
While implementing real Continuous integration in Salesforce, we need to perform various adjustments in metadata before deploying it to build server or production instance, many automated scripts (automation) are needed. If you need to change ANT scripts or metadata frequently, then it means continuous integration or deployment process in your Salesforce project is not yet fully matured.
There could be multiple situation where we don’t want some component to be deployed on production and example of one of them is List view.
When we include any custom or Standard object as a part of ANT deployment, it also includes listview created on that object. It is very common, that developer changes or creates multiple listviews for data analysis purposes. In that case, Listview created by customer could we overwritten after deployment and believe me, as a developer or consultant you don’t want to make customers unhappy 🙂 .
In this post, we will discuss how we can tweak Salesforce metadata dynamically in ANT with the help of xmlTask.
build.properties
xmlTaskjarFile=xmltask.jar root.dir=C:\\Users\\Jitendra\\Desktop\\Blog Demo
In above file, root.dir contains complete path till working folder and xmlTaskjarFile contains name of jar file downloaded from here. This jar file is placed in same location where build.properties exists.
Build.xml
<project name="Deployment Scripts" default="removeListViews" basedir="." xmlns:sf="antlib:com.salesforce"> <property file="build.properties"/> <property environment="env"/> <target name="removeListViews"> <taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" classpath="${xmlTaskjarFile}"/> <xmltask source="${root.dir}/src/objects/Account.object" dest="${root.dir}/src/objects/Account.object"> <remove path="/:CustomObject/:listViews"/> </xmltask> </target> </project>
As shown in above build.xml file, we have defined target by name removeListViews. This target can be called before Salesforce deployment target. It removes any listview found by using XPath from Account Object. Don’t forget to make a note of /: before CustomObject. I struggled a lot to identify why node is not being removed.
Download example of this post.
Leave a Reply