[SalesForce] RecordTypeInfo – isAvailable() returns true for Master Record Type

I am implementing an inline VF page where I need to show list of accessbile record types of Opportunities to user. It is also listing Master record type.
Following is the code,

for(RecordTypeInfo info: Opportunity.SObjectType.getDescribe().getRecordTypeInfos()) {
    if(info.isAvailable()) {
        System.debug('info - '+info);
    }
}

The current logged in user has no access to Master record type on profile. When I click on standard New opportunity button on tab I don't see master record type whereas I can see other record types accessible. I have also checked permission sets assigned to logged in user which also does not have access to Master record type.

Best Answer

I just tried mentioned code, and I have the same. Bug probably ? For me it is bug. Add few more lines of code to handle it:

for(RecordTypeInfo info: Opportunity.SObjectType.getDescribe().getRecordTypeInfos()) {
    if(isRecordTypeAvailable(info)) {
        System.debug('info - '+info);
    }
}

private Boolean isRecordTypeAvailable(RecordTypeInfo info){
    return info.isMaster() && !info.isDefaultRecordTypeMapping() ? false : info.isAvailable();
}

There are two possible scenarios to handle. In case, when there are other available recordtypes except Master, result of info.isMaster() && !info.isDefaultRecordTypeMapping() will be true and method isRecordTypeAvailable will return false. That means, that there is not only master available record type on object and user shouldn't have access to master. In case, when there is only master recordtype on object method will return true. So there is only master record type available and it is default, that means that user should have access to master recordtype.