Last active
February 11, 2016 07:51
-
-
Save nocrates/07342092bcac673b62e8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /* | |
| RecordTypeAccessor | |
| (c) Appirio, 2013 | |
| See https://gist.github.com/nocrates/5f8748b6ea6cdbba37a6 for test method and example usage | |
| */ | |
| public class RecordTypeAccessor { | |
| private static map<id,RecordType> recordTypeMap = new map<id,RecordType>([ | |
| SELECT Id, Name, DeveloperName, Description, BusinessProcessId, SobjectType, IsActive | |
| FROM recordtype | |
| ]); | |
| private static map<string,map<string,RecordType>> recordTypeByNameMap; | |
| static { | |
| recordTypeByNameMap = new map<string,map<string,RecordType>>(); | |
| for ( RecordType rt : recordTypeMap.values() ) { | |
| if ( !recordTypeByNameMap.containsKey( rt.SobjectType )) { | |
| recordTypeByNameMap.put( rt.SobjectType, new map<string,RecordType>() ); | |
| } | |
| recordTypeByNameMap.get(rt.SobjectType).put(rt.name,rt); | |
| } | |
| } | |
| public static RecordType getRecordTypeByName(string sobjectType, string pName) { | |
| if ( recordTypeByNameMap.containsKey(sobjectType) ) { | |
| if ( recordTypeByNameMap.get(sobjectType).containsKey(pName)) { | |
| return recordTypeByNameMap.get(sobjectType).get(pName); | |
| } | |
| } | |
| return null; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment