Guest User

Untitled

a guest
Nov 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. public with sharing class RecordTypeCache
  2. {
  3. public static Map<String, RecordType> get(SObjectType key)
  4. {
  5. return cache.containsKey(key) ? cache.get(key) : new Map<String, RecordType>();
  6. }
  7. public static RecordType get(SObjectType key, String developerName)
  8. {
  9. return get(key).get(developerName);
  10. }
  11.  
  12. static Map<SObjectType, Map<String, RecordType>> cache
  13. {
  14. get
  15. {
  16. if (cache == null)
  17. {
  18. cache = new Map<SObjectType, Map<String, RecordType>>();
  19. Map<String, SObjectType> objects = Schema.getGlobalDescribe();
  20. for (RecordType recordType : [SELECT DeveloperName, SObjectType FROM RecordType])
  21. {
  22. SObjectType schemaType = objects.get(recordType.SObjectType);
  23. if (!cache.containsKey(schemaType))
  24. cache.put(schemaType, new Map<String, RecordType>());
  25. cache.get(schemaType).put(recordType.DeveloperName, recordType);
  26. }
  27. }
  28. return cache;
  29. }
  30. private set;
  31. }
  32. }
Add Comment
Please, Sign In to add comment