Book Image

Force.com Enterprise Architecture

By : Andrew Fawcett
Book Image

Force.com Enterprise Architecture

By: Andrew Fawcett

Overview of this book

Table of Contents (20 chapters)
Force.com Enterprise Architecture
Credits
Foreword
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Implementing the custom query logic


If we take a look at the implementation of the fflib_SObjectSelector.selectSObjectById base class method (at the time of writing this book), it is quite simple and gives a template as to the way we can implement custom Selector methods; it also highlights other base class methods we can use:

public List<SObject> selectSObjectsById(Set<Id> idSet)
{
  assertIsAccessible();
  return Database.query(buildQuerySObjectById());
}
private String buildQuerySObjectById()
{ 
  return String.format(
    'SELECT {0} FROM {1} WHERE id in :idSet ORDER BY {2}', 
     new List<String> 
       {getFieldListString(),getSObjectName(),getOrderBy()}); 
}

The getFieldListString method calls the getSObjectFieldList and getSObjectFieldSetList methods implemented in the preceding code. It basically takes the SObjectField lists that result from these methods and builds a single comma-delimited list of fields ready to be inserted into the SOQL query string. Also, note...