21

I was wondering if it was possible to use any of the API's provided by SF to build an external (C#, Java) application to manage building changesets.

Building changesets is very tedious when trying to include 100's of items and I was hoping to streamline the process for our team by building an application I can load an excel file to with the required components and have it build the outbound changeset.

1
  • Have you looked into ANT?
    – Adrian Larson
    Commented Mar 20, 2016 at 21:53

3 Answers 3

4

Yes its possible. But rather than writing the application drom scratch in another language, consider keeping it on platform!

You can use the open source Apex Metadata API and custom metadata to define and push change sets. Here is a blog post by Andy Fawcett detailing the process: http://andyinthecloud.com/2015/06/28/custom-metadata-custom-uis-packaging-and-change-sets/

Metadata API source is here: https://github.com/financialforcedev/apex-mdapi

2
  • Thanks I'll take a look at this tutorial and plan out how to proceed @frup42
    – kknaguib
    Commented Mar 20, 2016 at 22:04
  • 10
    FYI, the link to Andrew Fawcett's blog post doesn't describe creation of a Change Set via an API. It describes pushing a custom metadata type from org to org using a change set.
    – Mark Pond
    Commented Sep 20, 2016 at 23:54
22

It turns out you can directly retrieve and update changesets directly with the Metadata API.

Via Sean Harrison‏:

Pro tip: U can retrieve the contents of a change set incl. manifest with the packageNames parameter on

And it really is that simple.


I made a test changeset in a sandbox with a single component:

enter image description here

Note the "Change Set Name" of TestCS.

Then over to Workbench for a migration retrieve:

enter image description here enter image description here

Complete the Retrieve and download the resulting package zip file: enter image description here

As part of the round trip exercise, extract the zip. Note the presence of the OpportunityBatchable.cls in the classes folder. Modify the package.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <fullName>TestCS</fullName>
    <description>Test Change Set. Updated locally!</description>
    <types>
        <members>OpportunityBatchable</members>
        <name>ApexClass</name>
    </types>
    <version>39.0</version>
</Package>

Zip the package back up. In this case it will have the TestCS folder at the root of the zip.

Back in workbench, use migration > Deploy. Select the modified zip file. Check "Auto Update Package". Press Deploy.

enter image description here enter image description here

Wait for the deployment to complete. Then reload the change set in Salesforce. Observe the updated Description!

enter image description here


So yes, you could build the changeset using Metadata API calls to update the package definition.


Updates via Chuck Liddell:

  1. Changeset names aren't unique. If there is a duplicate you will be an error:

    More that 1 developer package named "X" exists in this organization. Please rename one of packages so that is has a unique name. enter image description here

  2. On update, you can't have an empty package and rely on autoUpdatePackage. You need to include all the files that form the changeset.
13
  • 2
    Confirmed this also works with Salesforce DX (no real surprise, as DX is using MDAPI under the hood). Commented Dec 6, 2017 at 18:52
  • Question, though: It looks like in order to use this to modify the definition of the change set you had to upload all the components too. Is there any way to simply update the list of items in the change set without an update getting pushed into the org?
    – Charles T
    Commented Feb 22, 2018 at 18:46
  • @CharlesT I don't believe so. The change set needs to be self contained so it can be moved between orgs in isolation. If it didn't contain all the required metadata there would be problems when it arrived at the target org. Commented Feb 22, 2018 at 20:31
  • The idea though is, I have dev, QA and prod. I already pushed a big change set from dev to QA. After doing some weeks of QA (and making some changes in QA), I want to create a change set in QA containing exactly when I previously uploaded from dev. I don't want to overwrite the changes I made in QA, I just want all the items to now be in an outbound change set from QA.
    – Charles T
    Commented Feb 22, 2018 at 23:02
  • The best I can think of is, take the package.xml from Dev and use it to retrieve from QA. Then adapt the zip to target an outgoing change set and deploy the same thing back to QA again, so the change set now contains all the elements but nothing was overwritten. The only nag is that the "Last Modified" date of all those items will get bumped to the day of. Still that could be better than handpicking 300 items again.
    – Charles T
    Commented Feb 22, 2018 at 23:04
4

You can use salesforce Metadata API for this purpose . If you are familiar with ANT tool ,you will find that there is force.com migration tool in SFDC which uses ANT commands to help extract metadata and deploy to other orgs .

Package.xml is all needed by the migration tool to fetch necessary components from one org .

There are already many different tools build to automate the process of deployment .

1
  • Thanks yes I've used ANT to deploy metadata from my sandbox to our SIT sandbox before but haven't tried using it to package our entire deployment to prod. I will take a look at using it thanks! @mohith shrivastava
    – kknaguib
    Commented Mar 20, 2016 at 22:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .