Author Archives: Biswajeet

About Biswajeet

Biswajeet is my Name, Success is my Aim and Challenge is my Game. Risk & Riding is my Passion and Hard Work is my Occupation. Love is my Friend, Perfection is my Habit and Smartness is my Style. Smiling is my Hobby, Politeness is my Policy and Confidence is my Power.

Get Record Type Id With Dynamic sObject Name & Record Type Name

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;
    }