To lock records during the life of a transaction we use FOR UPDATE at the end of the SOQL statement. All good. One limitation is that you cannot use ORDER BY in conjunction with FOR UPDATE.
If I wanted to combine the effects of FOR UPDATE and ORDER BY on a result set, I could do a bubble sort on the recordset and use that.
My question is can I do this:
sObject lockedResultset = [select blah from blah where blah = 'blah' for update]; sObject orderedResultset = [select blah from blah where blah = 'blah' order by something];
and use the orderedResultset, whilst being confident that the records are locked (by virtue of the first SOQL query...)?
The pros of using the bubble sort is that we do only one query not two, and it might be fractionally quicker. Any thoughts?