Created
March 24, 2022 20:45
-
-
Save sauloefo/bdc7fa0500a6674977e7f8744ff7aac8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ExpensesSelector { | |
public static Map<Id, Expense> selectAll() { | |
return dataService.selectAll(); | |
} | |
private static ExpensesDataService dataService { | |
get { | |
if (null == dataService) { | |
// use with sharing by default | |
dataService = new WithSharing(); | |
} | |
return dataService; | |
} | |
set; | |
} | |
public static void switchSharing(Boolean useSharing) { | |
// this method is used to switch sharing model | |
if (useSharing) { | |
dataService = new WithSharing(); | |
} else { | |
dataService = new WithoutSharing(); | |
} | |
} | |
private abstract class ExpensesDataService { | |
public Map<Id, Expense> selectAll() { | |
return new Map<Id, Expense>([SELECT Amount, TransactionDate FROM Expense]); | |
} | |
} | |
private with sharing class WithSharing | |
extends ExpensesDataService { | |
} | |
private without sharing class WithoutSharing | |
extends ExpensesDataService { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment