A tried and true method for getting a RecordTypeId is the following line of code.
private static final Id RECORD_TYPE_NAME_RECORD_TYPE_ID =
Schema.SObjectType.<sObjectApiName>.getRecordTypeInfosByName().get('<Record Type Label>').getRecordTypeId();
I can't take credit for coming up with this one, but I did alter it slightly for clarity. Note that it uses the Label field rather than the DeveloperName field in spite of the method name. Additionally, the private
, static
, and final
modifiers may or may not be appropriate for your application.
I first discovered it at this blog. Now I use it all the time, especially in test code.