Guest User

Untitled

a guest
Feb 23rd, 2018
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. static Map<Id, Account> cache = new Map<Id, Account>();
  2.  
  3. Account[] getAccountsById(Set<Id> idSet) {
  4. Boolean complete = true;
  5. Account[] toReturn = new Account[]{};
  6.  
  7. for (Id id : idSet) {
  8. if (!cache.containsKey(id)) {
  9. complete = false;
  10. break;
  11. }
  12. toReturn.add(cache.get(id));
  13. }
  14. if (complete == true) return toReturn;
  15.  
  16. Account[] accList = [SELECT Name FROM Account];
  17. for (Account acc : accList) {
  18. cache.put(acc.Id, acc);
  19. }
  20. return accList;
  21. }
Add Comment
Please, Sign In to add comment