1

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.

2

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.

|improve this answer|||||
  • Currently in my profile Master has "Assigned Record Type" set to false. Hence I don't want it to be seen. Your solution will not work if I will set "Assigned Record Type" to true in future. Will it? Do you have any other workaround? – snehakem Sep 28 '17 at 12:54
  • @snehakem it will work in both scenarios, as I added condition && !info.isDefaultRecordTypeMapping() – Oleksandr Berehovskyi Sep 28 '17 at 12:55
  • Lets say I set for Master I will set "Assigned Record Type" to true. I will set some other record type as default. So info.isMaster() && !info.isDefaultRecordTypeMapping() = true && !false = true and hence it will return false. My Master is available so I would like to see it in my VF page but its returning false in this case. – snehakem Sep 28 '17 at 12:59
  • @snehakem it is not possible. You can't have master record type and any other to be available at same time. – Oleksandr Berehovskyi Sep 28 '17 at 13:01
  • @snehakem you can have available master record type (and it will be daefault for user) OR any other combination of custom record type(s). – Oleksandr Berehovskyi Sep 28 '17 at 13:05
0

The master record type is a placeholder record type when the system is set up out of the box. If there are no other record types then you will need to assign the page layout you would like your profiles to use to the master record type.

Once a custom record type is created the master record is no longer available for selection not only on page layouts but also on actions.

You can read more about this here https://help.salesforce.com/articleView?id=000005125&type=1

Quick fix for your code (Though I think you must be aware of this).

Boolean displayRecordType {get{if(displayRecordType == null) displayRecordType  = false; return  displayRecordType }; set;} // add this property in controller  

// Method for getting record type as picklist

 for(RecordTypeInfo info: Case.SObjectType.getDescribe().getRecordTypeInfos()) {
        if(info.isAvailable() && !info.isMaster()) {
            System.debug('info - '+info);
            displayRecordType = true;
        }
    }

Use rendered property for apex:selectList rendered = "{!displayRecordType }"

|improve this answer|||||
  • Currently in my profile Master has "Assigned Record Type" set to false. Hence I don't want it to be seen. Your solution will not work if I will set "Assigned Record Type" to true in future. Will it? Do you have any other workaround? – snehakem Sep 28 '17 at 12:55
  • Master record type can be assigned if there is no other record type is assigned. In controller you can check size of list of accessible record types. if it zero then don't render record type picklist on vf. – see modified answer – Amit Sep 28 '17 at 13:13
-1

Use following code and let me know if it does not work.

for(RecordTypeInfo info: Opportunity.SObjectType.getDescribe().getRecordTypeInfos()) {
    if(info.isAvailable() && info.isMaster() == false) {
        System.debug('info - '+info);
    }
}
|improve this answer|||||
  • 2
    info.isMaster() already returns a Boolean, instead of info.isMaster() == false simply use !info.isMaster() – Raul Sep 28 '17 at 12:36
  • This doesn't handle situation, when there is no custom recordtype on object. In this case, user should have access to master recordtype, but your code tells that user doesn't have access to master record type too. – Oleksandr Berehovskyi Sep 28 '17 at 12:54
  • Currently in my profile Master has "Assigned Record Type" set to false. Hence I don't want it to be seen. Your solution will not work if I will set "Assigned Record Type" to true in future. Will it? Do you have any other workaround? – snehakem Sep 28 '17 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.