Predictable Iteration Order for Maps and Sets

Salesforce on 1st April has notified a change to the iteration order for unordered collections (maps and sets). 

A map is a collection of key-value pairs where each unique key maps to a single value.
A set is a collection of unique elements.

It is changing the implementation for unordered collections to make the order of elements in those collections deterministic.
With this update, "The order of elements in maps and sets will be the same every time your code is run again."

On March 24, 2015, this change was released as a critical update in the application, which gives you control over testing and activating this change in your org. 

When you activate the critical update called "Predictable Iteration Order for Apex Unordered Collections" in Spring '15, the order of returned results is no longer arbitrary. The order of elements is deterministic - the order is the same every time you run the same code.

To make sure your code works perfectly even after the update:
Remove/Rewrite any Apex code that exercises order-dependent logic on unordered collections.

posted on 1 April 2015

Arbitrary Order Map Set Unordered Collection Apex