Record order consistency

Quite often, the order by clause is overlooked when writing SOQL queries, and this can lead to client/controller developers implementing this themselves. The default ordering of the platform is non-deterministic, though it sometimes appears to reflect the insert order, so the absence of an order by clause can often go unnoticed in testing. By using a Selector, you can apply a default order sequence to all Selector methods.

Returning Map<Id, SObject> instead of List<SObject> might seem like a good way to help callers process the information. Maps in Apex have a predictable iterator order; however, it is not clear from the documentation whether this is the order in which items are added to the map. If you're concerned about this, keep in mind that the result of using the order by clause in the Selector might be affected if Map is used. Given the ease with which maps by SObject ID are created by passing the list into the Map constructor, it's often best to leave this option to wrap or not wrap the list returned up to the calling code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.35.185