Skip to content

Instantly share code, notes, and snippets.

@nocrates
Last active February 11, 2016 07:51
Show Gist options
  • Select an option

  • Save nocrates/07342092bcac673b62e8 to your computer and use it in GitHub Desktop.

Select an option

Save nocrates/07342092bcac673b62e8 to your computer and use it in GitHub Desktop.
/*
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