package xml using changeset

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

General Development

Prerequisites: Force.com 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 Force.com Migration Tool. https://developer.salesforce.com/docs/atlas.en-us.daas.meta/daas/forcemigrationtool_install.htm

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

changeset_sfdcmonkey-package.xml

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

	<property file="build.properties" />
	<property file="secret.properties" />
	<property environment="env" />

    <property name="maxPoll" value="1000" />
    <property name="defaultPackageFolder" value="package" />
    <property name="devPackageFolder" value="package-dev" />
	<property name="salesforceUrl" value="https://test.salesforce.com" />

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

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

			<input message="Please enter the name of the change set:"
				   addproperty="source.changeSetName"
			/>
			<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}"
						 password="${password}"
						 serverurl="${salesforceUrl}"
						 maxPoll="${maxPoll}"
						 retrieveTarget="@{folder}"
						 packageNames="${source.changeSetName}" />
		</sequential>
	</macrodef>

	<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" />
    </target>

</project>
  • Above code has operation called ‘retrieve-cs’, that retrieves Change Set components from your Sandbox. Make sure username and password variables in build.properties 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 Force.com Migration Tool and Change Sets

2 comments

Leave a Reply