Wednesday, August 14, 2019

How to get Default Record Type Id of object using apex in salesforce

In this example, I am getting Account object default record type Id

Example
Schema.DescribeSObjectResult describeResult = Account.getsObjectType().getDescribe();
List<Schema.RecordTypeInfo> rtInfos = describeResult.getRecordTypeInfos();
for(Schema.RecordTypeInfo rtInfo : rtInfos) {
    
    if(rtInfo.isDefaultRecordTypeMapping()) {       
        System.debug('Default Record Type Id ====> '+rtInfo.getRecordTypeId());
    }
}  

Result

No comments:

Post a Comment