All Collections
Comparisons and deployments
Why is XML order of some metadata in the comparison results different?
Why is XML order of some metadata in the comparison results different?

Salesforce metadata API returns the XML in non-deterministic manner

Sravani Bhattiprolu avatar
Written by Sravani Bhattiprolu
Updated over a week ago

In some cases, items in the comparison results show up as Different, but when you look at the XML, the difference is purely in the order of the XML elements.

In the screenshot below, the source and target XML have the same meaning, but lines 8 and 13 are returned in a different order. As a result, this shows up as a difference to Gearset. In some ways, this is a false positive, as the overall meaning of the item is the same in both environments. 

One of the most common examples of this is the custom object metadata type as shown in the screenshot below.

Why does this happen?

This happens because the Salesforce metadata API is not always consistent in the XML order when returning XML elements. 

Without changing the meaning of the org's metadata, the ordering of the XML elements of the same org can also be different between two consecutive retrievals.

Gearset’s comparison engine then sees this as a difference in the file, as the XML has been changed.

Why doesn’t Gearset ignore XML reordering? 

We sometimes get asked if we can re-order the XML elements to remove these false positive “changes” from the comparison results. There are two reasons the app doesn’t do this by default:

  1. The XML order is important for some elements - e.g. picklists. If we were to re-order the XML, the order of the picklist values would be altered, which introduces unwanted changes in the deployment.

  2. Which metadata types are affected, and the nature of the reordering, is inconsistent in the metadata API. This makes it hard to reliably predict which components are expected to have false positives, and which are genuine ordering differences.

If this is not the behavior you need - there is the option to Simplify differences in the following way:

From November 2021, Gearset has started to set the hide re-ordering (now Simplify differences) by default or ignore the re-ordering on the following metadata types:

  • Clean data service

  • Connected app

or applying the "re-ordering logic" when determining the Difference Type in the Difference type column metadata types:

  • Custom Object

If you think there are other metadata types that Gearset should hide for you by default, please get in touch with us.

Did this answer your question?