Popular Posts

Monday, April 15, 2013

Get Record Type Id of SObject without Query to Salesforce


Hi Folks,

Now you can get recordTypeId of any Salesforce sObject without query by using following method...

// ----------------------------------------------------------------------------------------------------
public static id GetRecordTypeId(string objectAPIName, string recordTypeName){
        if(IsNullOrEmptyString(objectAPIName) || IsNullOrEmptyString(recordTypeName)){
            return null;
        }
        if(sobjectSchemaMap == null)
        {
            sobjectSchemaMap = Schema.getGlobalDescribe();
        }
        Schema.SObjectType sObjType = sobjectSchemaMap.get(objectAPIName) ;
        Schema.DescribeSObjectResult cfrSchema = sObjType.getDescribe() ;
        Map<String,Schema.RecordTypeInfo> RecordTypeInfo = cfrSchema.getRecordTypeInfosByName();
        Id recordTypeId = RecordTypeInfo.get(recordTypeName).getRecordTypeId();
        return recordTypeId;
    }
// ----------------------------------------------------------------------------------------------------------

No comments:

Post a Comment