0

In my visualforce page I have two command button. I want to store boolean value into database against those radio button. I have chosen the field type as 'checkbox'. Please help me.

My vf code is

<apex:page standardStylesheets="false" controller="RadioButtonTestController" showHeader="false" sidebar="false">
<apex:form >
    <div align="center">

        <apex:selectRadio value="{!Country}" > 
           India <apex:selectOption itemValue="true"></apex:selectOption>&nbsp;&nbsp;
          China &nbsp;&nbsp;<apex:selectOption itemValue="false"></apex:selectOption>

            <apex:actionSupport event="onchange" 
                    action="{!checkSelectedValue}" 
                    reRender="none"/>
            </apex:selectRadio>

        <apex:commandButton value="Show country" action="{!showCountry}"/>
    </div>
</apex:form>

My Controller is: `

public class RadioButtonTestController 

{ public Boolean Country{get; set;} public void checkSelectedValue() {

    system.debug('Selected value is: '+ Country);
}

public void showCountry()
{
    String caseId = ApexPages.currentPage().getParameters().get('CaseID');
    list<Storing_Location__c> str = [Select Country__c from Storing_Location__c where CaseNumID__c=: caseId];
    Storing_Location__c obj = new Storing_Location__c();
    if(str.size()>0)
    {
        obj.Id = str[0].Id;
    }

    obj.Country__c = Country;
    system.debug('Selected value is:***********************:::'+Country);

}

}

  • where is your controller? how are you planning to do this, what exactly is the problem you are facing? – glls Aug 11 '17 at 13:26
  • I used radio button before and stored values in string. But in this case how can I store boolean values? And to do that what is the field type? – Sam Aug 11 '17 at 13:29
  • What you are planning to do with radio button – salesforce Developer Aug 14 '17 at 6:13
  • My requirement is to store Boolean value for those two radio button in Country__c which is a checkbox type field. – Sam Aug 14 '17 at 12:11
  • When you say "I have chosen the field type as 'checkbox'", what is the field and object you mean? Is it the Country__c field in Storing_Location__c object? – David Cheng Aug 18 '17 at 19:36
0

I got a solution myself

The controller should be:

enter image description here

Here the database field "Country__c" is checkbox type. So it takes only Boolean value. If User select "India" then field "Country__c" will be checked otherwise not.

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.