Since quite a while we are able to sort on any fields with Record.SetCurrentKey(), even if the fields is not part of a defined key (even though not documented, but reported as document bug).
The corresponding functionality is missing on RecordRef.
On RecordRef we can only set sorting with the RecordRef.CurrentKeyIndex() function, which is bound to the defined Keys on the table.
I have a scenario where I need to find the maximum or minimum value of a given field, but without being able to sort on the specific field I have to loop all records to find out the largest/smallest value and this can of course have a huge negative impact on performance.
I suggest to add a new function on RecordRef with the following signature
RecordRef.SetAscending([FieldNo: Integer [, Ascending: Boolean]])
Parameters:
FieldNo: The number of the field that should be sorted on. If omitted, the sorting for RecordRef would be reset to the primary key in ascending order (similar as RecordRef.Reset(), but it doesn't reset filters)
Ascending: Specifies true if the field should be sorted in ascending order; otherwise false. Default is true.
To sort on more than one field, RecordRef.SetAscending should be called once for each field.
To first sort the RecordRef by field number 1 and then on field number 2:
RecordRef.SetAscending(1);
RecordRef.SetAscending(2);
To first sort the RecordRef by field number 1 descending and then on field number 2 ascending:
RecordRef.SetAscending(1, false);
RecordRef.SetAscending(2);

Business Central Team (administrator)
Thank you for this suggestion! Currently this is not on our roadmap. We are tracking this idea and if it gathers more votes and comments we will consider it in the future. Best regards, Business Central Team