Sharing conventions

As stated in the previous chapter, it is good practice to explicitly indicate which sharing mode you want your query logic to run in by default. Thus, every Selector class should use the inherited sharing keyword, as shown in the following example. If you follow the convention outlined for your Service class, the with sharing context will be inherited. The following example shows the best practice to always define inherited sharing:

public inherited sharing class RacesSelector

By using inherited sharing, this does allow for all the queries in the Selector class to be called within a without sharing context when this is enabled by the calling class. However, if you consider sharing as a form of record filtering, much like the logic expressed in the WHERE clause, then the encapsulation of this type of filter criteria also truly belongs as an internal implementation concern within the Selector class. So, if you require that some SOQL queries are executed within the Selector code using the without sharing context and others the inherited context, then I recommend using the Elevate pattern within the Selector class, as described in the Sharing rules enforcement section of Chapter 5Application Service Layer. One example of the elevate pattern is a query that summarizes race data when some of the race data may not be visible to the current user, but the result must still represent all race data.

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

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