Implementing custom query logic
If we take a look at the implementation of the selectSObjectById
base class method we have been using so far in this chapter, the buildQuerySObjectById
method code shown as following, gives an indication of how we implement custom Selector methods; it also highlights the newQueryFactory
base class method usage:
public List<SObject> selectSObjectsById(Set<Id>idSet) { return Database.query(buildQuerySObjectById()); } private String buildQuerySObjectById() { return newQueryFactory(). setCondition('id in :idSet'). toSOQL(); }
The newQueryFactory
method exposes an alternative object orientated way to express a SOQL query. It follows the fluent design model with its methods making the configuration less verbose. For more information on this approach see https://en.wikipedia.org/wiki/Fluent_interface.
The instance of fflib_QueryFactory
returned by this method is preconfigured with the object, fields, order by and any field set...