2

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

2

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:PageBlockSection> 
                    <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>
                        </apex:selectRadio>
                    </apex:PageBlockSectionItem>
</apex:PageBlockSection>

You can use and rerender attribute to render Tables accordingly.

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

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.