Generate Salesforce package.xml programmatically

There are already some open sourced tools for this task .One of them is as below

https://packagebuilder.herokuapp.com/

You can also use eclipse to the do this .In eclipse once you selected compoenents and fetch the package xml file is formed .


Here is what you need to do:

  1. You need the ability to fetch the metadata details from the org. If you want to do this in Apex, you might want to check out the Apex Wrapper Salesforce Metadata API.
  2. You could use the Salesforce REST APIs for Metadata and do this in javascript example (by creating a chrome extension?). You can check out the source code of this chrome extension "Salesforce Inspector" which effectively utilizes the metadata of the org to provide awesome time saving utlity.
  3. Not to forget you would also need to understand how does the package.xml look like for each of the selected component. This information is documented very well here.
  4. Once you know whats the metadata and how to fetch it, and how the package.xml looks like. It is only about putting these pieces together and automating the process.

    I remember discussing with someone reg. an utility wherein the developer could provide the start and enddates on a form. The page would display all the metadata (classes,objects,fields etc.) created/modified in the org during that time period. The user could then select any/all of the selected components and upon a button click a package.xml would be generated automatically. Are you working on something similar? Something like this(not sure if it exists already!) would be very helpful!


I would highly suggest looking into the MavensMate API to accomplish any programmatically built package.xml. There is some great documentation on the API to point you in whatever direction you are looking to go with your project and examples for doing various operations.

The MavensMate plugin for SublimeText has a really nice UI for editing Package.xml's as well, and I highly recommend it as an IDE.