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
babloo123babloo123 

Controller to save Radio buttons selected option as picklist in Object

Can any one help how to write controller code for below question on VF pagehaving radio buttons to store value as picklist in object. Question is below

Have you Served as Manager
Radio buttons
Yes
No

In application the quuestion has picklist Yes and NO. Can some one help how the controller should be written to svae a radio button selected option on VF page to save as picklist in Object.
Andreas MeyerAndreas Meyer
Hi,

try this:

/*** VF page ***/
<apex:page controller="managerController">
....


    <apex:form>
        <apex:selectRadio value="{!manager}">
            <apex:selectOptions value="{!items}"/>
            </apex:selectRadio><p/>
            <apex:commandButton value="send" action="{!savemanager}"/>
     </apex:form>

....
</apex:page>


/*** Controller ***/
public class managerController {
    String manager = null;
    MyObject__c mycustomobject; // this is you custom object with the picklist field


    public managerController() {
	// get your custom object
        this.mycustomobject = [SELECT ....];
    }

         
    public PageReference savemanager() {
	
	// now transfer the radio value to your custom object picklist field
	this.mycustomobject.custom_picklist_field__c = this.manager;
        return null;
    }
                
    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>(); 
        options.add(new SelectOption('Yes','Yes')); 
        options.add(new SelectOption('No','No')); 
        return options; 
    }
                   
    public String getManager() {
        return manager;
    }
                    
    public void setManager(String manager) { this.manager = manager; }
}

Best,
Andreas