I believe that I have found very interested undocumented bug in Salesforce.
I don't see in the documentation saying that List.sort method implementation depends on version, but looks like it does. If one reads SFDC Documentation on List sort method here and here, one may get impression that for list of SObject records of the same type with different names, the sort method will always sort them by name disregarding the version of class where the sort method is called, but it is wrong impression.
In fact, if you moved a single line of code
projects.sort()
from a controller class with version 37 to some DAO class of version 19 you may find that list of SObject records now are sorted in some wrong order. They are no longer sorted alphabetically by the name. If you call that method again in controller class with version 37, the records will be sorted correctly. Also if you change the version of DAO Class from version 19 to version 37, the records will be also sorted as expected.
I wonder why the implementation of sort method has changed?
Does anyone know in which order Salesforce sorts SObject records if using version 19?
sObjects
and also refers to custom sorts usingcomparable
in wrapper classes which is not the same as the system method oflist.sort()
. The default sort order is ascending for both. It would be helpful if you provided details of the discrepancy you're seeing between the two different APIs. Right now, you've provided no examples to support your assertion of a difference nor in which type of sorting between APIs.label of the sObject type
and then theName
of thesObject record
, followed by Standard Fields in alphabetical order (if Name matches), then by Custom Fields in alphabetical order. In right in the 1st set of documentation you linked to. Thus the reason I asked for examples.