Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public with sharing class RecordTypeCache
- {
- public static Map<String, RecordType> get(SObjectType key)
- {
- return cache.containsKey(key) ? cache.get(key) : new Map<String, RecordType>();
- }
- public static RecordType get(SObjectType key, String developerName)
- {
- return get(key).get(developerName);
- }
- static Map<SObjectType, Map<String, RecordType>> cache
- {
- get
- {
- if (cache == null)
- {
- cache = new Map<SObjectType, Map<String, RecordType>>();
- Map<String, SObjectType> objects = Schema.getGlobalDescribe();
- for (RecordType recordType : [SELECT DeveloperName, SObjectType FROM RecordType])
- {
- SObjectType schemaType = objects.get(recordType.SObjectType);
- if (!cache.containsKey(schemaType))
- cache.put(schemaType, new Map<String, RecordType>());
- cache.get(schemaType).put(recordType.DeveloperName, recordType);
- }
- }
- return cache;
- }
- private set;
- }
- }
Add Comment
Please, Sign In to add comment