Coding-With-The-Force / Salesforce-Separation-Of-Concerns-And-The-Apex-Common-Library

This repo hopes to better explain Separation of Concerns for Salesforce and how to leverage the Apex Common library to employ it in your org.
88 stars 19 forks source link

Update Wiki for the new Apex Database Access modes. #7

Open bdJohnson72 opened 1 year ago

bdJohnson72 commented 1 year ago

As of Dec 22nd the fflib_Selector was updated to use the Apex Data Access modes in its constructor.

Below is an example of a selector class that is set to run in usermode by default via the constructor. We must also provide a value for the use of field sets.

public inherited sharing class AccountSelector extends fflib_SObjectSelector {

    public AccountSelector(){
        super(false, DataAccess.USER_MODE);
    }

    public SObjectType getSObjectType() {
        //All selectors must implement
        return Account.SObjectType;
    }

    public List<SObjectField> getSObjectFieldList() {
        //All selectors must implement
        return new List<SObjectField>{
                Account.Id,
                Account.Name,
                Account.AccountNumber,
                Account.Industry,
                Account.Rating,
                Account.NumberOfEmployees
        };

    }   
}

If we want the selector to run in System mode, we configure that at the instance level.

AccountSelector accountSelector = new AccountSelector();
accountSelector.setDataAccess(fflib_SObjectSelector.DataAccess.SYSTEM_MODE);

An example query string would look like the following. _SELECT id, name, accountnumber, industry, rating, numberofemployees, type, description FROM Account WITH SYSTEMMODE ORDER BY Name ASC NULLS FIRST
LIMIT 10