In the new Platform, Fonteva is introducing service classes alongside a new paradigm to search for records. We have created a new object called FDService.SearchRequest, which controls every aspect querying. We want all interactions to happen using wrapped objects instead of straight SObjects.

Search Request Javadoc

This class allows end users to provide the following:

  1. Custom where clause
  2. Reduced number of fields instead all fields from objects
  3. Fields from related objects
  4. Limit and Sort By
  5. Ability to disable access permissions based on query
  6. Select directly by Id or set of Id's


Simple Select By Id Example


The above example is a simple use of the FDService.SearchRequest that allows the user to select by ids. This will pull all fields the requesting user has access to and return the wrapped objects.

Advanced Example using filtering and order by

List<FDService.Catalog> tempCatalogs = FDService.CatalogService.getInstance().get(FDService.SearchRequest.getInstance()
        .filter('OrderApi__Store__c = {0} AND OrderApi__Is_Published__c = true',new List<Object>{storeId})
        .orderBy('OrderApi__Display_Order__c ASC NULLS LAST'));

The above example is a more advanced use of FDService.SearchRequest that allows chained methods and filtering. We are able to provide a SOQL where clause with tokens that will be replaced at run time. The platform will auto-add quotes and escape the string for you. The second parameter for filter is what those tokens should be replaced with. From there, you can provide who the query should run as and the order by. All of these methods are chained so they are easier to read.

Filtering Example with IN clause

FDService.TermService.getInstance().get(FDService.SearchRequest.getInstance().filter('OrderApi__Subscription__c IN ({0})',new List<Object>{subIds}))

In the above example, you can see that we also support IN queries. All you need to provide is the token number and the values in the second parameter. The rest will be taken care of by the platform.