How to get recordTypeId using record type name?

How to get recordTypeId using record type name?

Sample Code:


        String strObject = ‘Account’;
        String rtName = ‘Marketing’;

        Schema.DescribeSObjectResult d = getDescribSObject(strObject);        
        Map<String,Schema.RecordTypeInfo> rtMapByName = d.getRecordTypeInfosByName();
        Schema.RecordTypeInfo rtByName = rtMapByName.get(rtName);
        Id recTypeId = rtByName.getRecordTypeId();



        public static Schema.DescribeSObjectResult getDescribSObject(String strObject) {
            Schema.DescribeSObjectResult d;
            if(strObject.equals(‘Account’)) {
                        d = Schema.SObjectType.Account;
                }
        }


(Or)


Id devRecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get(‘Advisors’).getRecordTypeId();


Cheers!!!

Leave a Reply