Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static Map<Id, Account> cache = new Map<Id, Account>();
- Account[] getAccountsById(Set<Id> idSet) {
- Boolean complete = true;
- Account[] toReturn = new Account[]{};
- for (Id id : idSet) {
- if (!cache.containsKey(id)) {
- complete = false;
- break;
- }
- toReturn.add(cache.get(id));
- }
- if (complete == true) return toReturn;
- Account[] accList = [SELECT Name FROM Account];
- for (Account acc : accList) {
- cache.put(acc.Id, acc);
- }
- return accList;
- }
Add Comment
Please, Sign In to add comment