package xml using changeset

How To Generate package.xml Through Migration Tool and Change Sets

General Development

Prerequisites: Migration Tool [ANT]. This is one of the popular deployment tools used for migrating Salesforce metadata from one org/sandbox to another. Check this link for Installation details if you don’t already have Migration Tool.

Follow below steps to generate package.xml

  • Go to Setup and create a Change Set in your sandbox. You cannot test this feature with Developer edition since Developer edition doesn’t come with any sandboxes


  • Copy below script and paste it into build.xml file
<project name="Salesforce Retrieval Package" default="" basedir="." xmlns:sf="antlib:com.salesforce"
		 xmlns:xsi="" xsi:schemaLocation="antlib:com.salesforce">
    <taskdef resource="net/sf/antcontrib/antlib.xml"/>

	<property file="" />
	<property file="" />
	<property environment="env" />

    <property name="maxPoll" value="1000" />
    <property name="defaultPackageFolder" value="package" />
    <property name="devPackageFolder" value="package-dev" />
	<property name="salesforceUrl" value="" />

	<target name="-prompt" unless="hidePrompt">
		<input message="${promptMessage}"
		<condition property="do.abort">
			<equals arg1="n" arg2="${do.delete}" />
		<fail if="do.abort">Build aborted by user.</fail>

	<macrodef name="retrieve-cs">
		<attribute name="folder" />
		<attribute name="prompt" default="true" />
			<condition property="hidePrompt">
                    <isset property="jenkins"/>
                    <equals arg1="@{prompt}" arg2="false" />

			<input message="Please enter the name of the change set:"
			<property name="promptMessage" value="Are you sure you want to retrieve a change set from the following org?${line.separator}
			salesforceUrl: ${salesforceUrl}${line.separator}
			username:      ${username}${line.separator}
			changeSet:     ${source.changeSetName}${line.separator}
			folder:        @{folder}${line.separator}" />
			<antcall target="-prompt" />

			<mkdir dir="@{folder}" />
			<sf:retrieve username="${username}"
						 packageNames="${source.changeSetName}" />

	<target name="retrieve-cs" description="Retrieves package metadata components from a specified change set in the source org.">
        <!--<retrieve-cs folder="${defaultPackageFolder}" />-->
		<retrieve-cs folder="changeSet" />

  • Above code has operation called ‘retrieve-cs’, that retrieves Change Set components from your Sandbox. Make sure username and password variables in are same as in build.xml
  • Run ‘ant retrieve-cs’ command in command prompt/terminal. Enter the change set name when prompted and confirm the operation. Script should create a new folder called changeSet and stashes the components from Change Set in to the same. If everything is okay, you should see that build is successful like below

changeset to package.xml

Check also :  How to Find Salesforce Object ID prefixes (custom or standard)

Happy Coding!

About The contributor: 

Suneel Pelluru

1 Post Contribute

Suneel Pelluru sfdcMonkey blog contributor

Suneel is a Senior Salesforce Developer working for Indeed in Austin, Texas.








Blogs By Suneel :

  1. How To Generate package.xml Through Migration Tool and Change Sets


Leave a Reply