function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Bhargav krishna 1Bhargav krishna 1 

radio button in custom object

Hi everyone,
I want to display the Gender selection with radio buttons as shown in below image in Custom object
User-added image
Can anyone help me over here.
Thanks in advance.
Regards,
Bhargav.
JyothsnaJyothsna (Salesforce Developers) 
Hi Krishna,

You can't create a Radio button through Configuration in the model. If you want radio buttons, you need to customize your standard page using APEX. Here is the sample example for the radio button. Based on your requirement you can change the names.

Visualforce Page:
 
<apex:page controller="sampleCon">
<apex:form >
<apex:selectRadio value="{!country}">
<apex:selectOptions value="{!items}"/>
</apex:selectRadio><p/>
<apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
</apex:form>
<apex:outputPanel id="out">
<apex:actionstatus id="status" startText="testing...">
<apex:facet name="stop">
<apex:outputPanel >
<p>You have selected:</p>
<apex:outputText value="{!country}"/>
</apex:outputPanel>
</apex:facet>
</apex:actionstatus>
</apex:outputPanel>
</apex:page>

Controller:
 
public class sampleCon {
String country = 'CANADA';

public PageReference test() {
return null;
}
public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('US','US'));
options.add(new SelectOption('CANADA','Canada'));
options.add(new SelectOption('MEXICO','Mexico')); return options;
}
public String getCountry() {
return country;
}
public void setCountry(String country) { this.country = country; }
}

Hope this helps you!
Best Regards,
Jyothsna
Naresh YadavNaresh Yadav
Hi bhargav

just use the below code in your VF page
 
<apex:selectRadio value="selectedOption">     
    <apex:selectOption itemlabel="Male" itemValue="Male"/>     <apex:selectOption itemlabel="Female" itemValue="Female"/> 
</apex:selectRadio>


Mark it as solution if it helps you out.
Thanks
​Naresh