I have two record types on a custom object and I have to show them as radio buttons on the visualforce page and render pageblock tables accordingly.I am unable to fetch record type name and display them as labels. Any help will be appreciated

1 Answer 1


You can try this

Apex Class :

public String SelectedRecordType {get ;set;}
public List<selectOption> getRecordTypes()
    List<selectOption> rTypes = new List<selectOption>();    
    for (RecordType  a : 
            [Select Id, Name,DeveloperName FROM RecordType 
            where SobjectType = 'Your_Custom_Object_Name__c']) 
                rTypes.add(new selectOption(a.Id, a.DeveloperName ));
    return rTypes; 

Visualforce Page :

                    <apex:PageBlockSectionItem >    
                        <apex:outputLabel value="Record Types:" for="Types"/>              
                        <apex:selectRadio value="{!SelectedRecordType}" id="rTypes" layout="pageDirection" style="margin-top:-10px;margin-left:-18px">
                            <apex:selectOptions value="{!RecordTypes}"> </apex:selectOptions>

You can use and rerender attribute to render Tables accordingly.

It is ESSENTIAL to request RecordTypes by DeveloperName please Check here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .