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
Umesha BP 9Umesha BP 9 

How to store radio button Values into Pick list Value?

Scenario:
I have one pick list field in Candidate Object
Do you Know Java?
Options:Yes and No
In visualforce I am displaying In radio Button .
If I select Yes I want to update Do_You_kNow_java__c is Yes
If I select No I want to update Do_You_kNow_java__c is No
in picklist field.
Please Explain How to do ?
NagendraNagendra (Salesforce Developers) 
Hi Umesha,

Please find the sample code below and tweak it as per your requirement.

Use Case: I have a picklist field with values 'yes' and 'No' I want to show this field as radio buttons on my VF page. i.e. one radio button for yes and one for no. and at a time only one can be selected

Note that type__c is my picklist field.
 
Use following method to get options for radio button on page
controller code:
public List<SelectOption> getTypes(){
            Schema.sObjectType sobject_type = customObject__c.getSObjectType();
            Schema.DescribeSObjectResult sobject_describe = sobject_type.getDescribe();
            Map<String, Schema.SObjectField> field_map = sobject_describe.fields.getMap();
          
            List<Schema.PicklistEntry> pick_list_values = field_map.get('type__c').getDescribe().getPickListValues();
            List<selectOption> options = new List<selectOption>();
           for (Schema.PicklistEntry a : pick_list_values) {
                      options.add(new selectOption(a.getLabel(), a.getValue()));
          }
      return options;
 
to use this on page:
 
<apex:selectRadio value="{!customObject__c.Type__c}">
                    <apex:selectoptions value="{!types}"></apex:selectoptions>
 </apex:selectRadio>
Hope this helps.

Please mark this as solved if the information helps so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks,
Nagendra