Ordering

As mentioned in the Naming conventions section, having a default order to records is important so as to avoid the random non-deterministic behavior of the platform SOQL engine. The selectsObjectById base class method calls the getOrderBy method to determine which field(s) to use in order to order the records returned from the Selector.

The default behavior is to use the Name field (if available, otherwise CreatedByDate is used). As such, the previous usage is already ordering by Name without further coding. If you wish to change this, override the method as follows. This example is used by the ContestantsSelector class to ensure that contestants are always queried in the order of season, race, and their race position:

public override String getOrderBy() { 
  return 'Race__r.Season__r.Name, Race__r.Name, RacePosition__c'; 
}

Later in this chapter, you will see how custom Selector methods can be constructed; these have the option of using the getOrderBy method. This allows some methods to use a different order by clause other than the default if you wish to do so.

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

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