Sample Methods:
//Get recordTypeId by Object Name & Record Type Name public static Id recordTypeIdByName(string objAPIName, string recTypeName){ Id recTypeId; if(String.isNotBlank(objAPIName) && String.isNotBlank(recTypeName)){ recTypeId= Schema.getGlobalDescribe().get(objAPIName).getDescribe().getRecordTypeInfosByName().get(recTypeName).getRecordTypeId(); } return recTypeId; } //Get recordTypeId by Object Name & Record Type Developer Name public static Id recordTypeIdByDevName(string objAPIName, string recTypeDevName){ Id recTypeId; if(String.isNotBlank(objAPIName) && String.isNotBlank(recTypeDevName)){ recTypeId= Schema.getGlobalDescribe().get(objAPIName).getDescribe().getRecordTypeInfosByDeveloperName().get(recTypeDevName).getRecordTypeId(); } return recTypeId; } //Get all recordTypeId Map (Name as key and recordTypeId as value) by Object Name public static Map<String,Id> recordTypeMap(string objAPIName){ Map<String, Id> recTypeNameIdMap = new Map<String,Id>(); if(String.isNotBlank(objAPIName)){ for(Schema.RecordTypeInfo recInfo : Schema.getGlobalDescribe().get(objAPIName).getDescribe().getRecordTypeInfosByName().values()){ recTypeNameIdMap.put(recInfo.getName(),recInfo.getRecordTypeId()); } } return recTypeNameIdMap; } //Get Record Type Id or developer name by passing developer name or Id public static string getRecordTypeInfoByIdOrDeveloperName(String recordType){ string returnValue = ''; Boolean isValidId = recordType instanceOf Id; for(Schema.SObjectType objType : Schema.getGlobalDescribe().Values()){ Schema.DescribeSObjectResult doResult = objType.getDescribe(SObjectDescribeOptions.DEFERRED); if(isValidId){ if(doResult.getRecordTypeInfosById().get(recordType) != null){ returnValue = doResult.getRecordTypeInfosById().get(recordType).getDeveloperName(); break; } }else{ if(doResult.getRecordTypeInfosByDeveloperName().get(recordType) != null){ returnValue = doResult.getRecordTypeInfosByDeveloperName().get(recordType).getRecordTypeId(); break; } } } returnValue; }