Using XMLTask in ANT for Salesforce Deployment

Dynamically remove XML content from metadata before Salesforce deployment using xmlTask – Video

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.

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 exists.


<project name="Deployment Scripts" default="removeListViews" basedir="." xmlns:sf="antlib:com.salesforce">
    <property file=""/>
    <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"/> 

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.




Related Posts


4 responses to “Dynamically remove XML content from metadata before Salesforce deployment using xmlTask – Video”

  1. Peter Avatar

    Thanks for the nice Post,
    Please suggest, how to deploy profile listview using Ant

  2. devaggarwal99 Avatar

    Nice Post.
    Any thoughts on how can we make this more dynamic by avoiding hardcoding of filenames and removing listviews from all the files at one go.

  3. devaggarwal99v Avatar

    To Make this more dynamic and avoid hardcoding files names,
    I recommend using a for loop (ant-contrib) package and iterating over the complete library.

  4. Joe Avatar

    “Don’t forget to make a note of /: before CustomObject. ”

    Why do we need colon (:) after the slash (/) for node name. All the example I see for xmltask don’t use colon.

    How do I know when to use colon or not?


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading