In my Visual force page I am showing all the cases related to a contact. I use a search function to populate the value of cases in a List of a wrapper class. I am mimicking from this link->https://developer.salesforce.com/page/Wrapper_Class

Here is my wrapper class:

 public class cContact{

    public Case con{get;set;}
    public Boolean selected{get;set;}

    public cContact(Case c){



My logic in controller extension:

public List<cContact> contactList {get; set;}

 public Pagereference search() {

if(contactList == null){
  contactList = new List<cContact>();
     for(Case c: [Select Id, CaseNumber, Status, Subject from Case where contact.Name = : first + ' ' + last]) {
        // As each contact is processed we create a new cContact object and add it to the contactList
        contactList.add(new cContact(c));
  return null;

My logic in VF page to display radio button selection for each row in PageBlockTable:

<apex:pageblockTable value="{!contactList}" var="c" id="caselist">
                    <apex:column >
                    <!-- This is our selected Boolean property in our wrapper class -->
                    <apex:selectRadio value="{!c.selected}"/>
                <apex:column value="{!c.con.Id}" />
                <apex:column value="{!c.con.CaseNumber}" />
                <apex:column value="{!c.con.Status}" />

I can see the radio button , but it seems like all the radio button are independent of each other, meaning- I can select all the radio button at a time ( I should only be able to select one at time!). How can I correct this?

enter image description here

  • hmm.. then One I idea I want to suggest.. onclick of checkbox call a method in controller and assign current record Id to any variable. After that in that called method iterate over all the wrapper list and check the assigned record Id. If matched then that wrapper boolean make true and all other wrapper boolean make false..
    – Ratan Paul
    Apr 18 '16 at 5:56
  • or on click call Javascript method where get all other radio button and make them false. Apr 18 '16 at 6:03
  • @sfdcweb I guess Onclick I can only call a javaScript method, is that correct? When I tried to have a method like public void selectedRadio(){ } in my extension and use <apex:selectRadio value="{!c.selected}" onclick="{!selectedRadio}"/> there was an error-Unknown property 'ContactStandardController.selectedRadio'
    – SfdcBat
    Apr 18 '16 at 6:06
  • 1
    Try html <apex:column headervalue="Cases"> <input type="radio" name="group" id="{!exscases.Id}" /> </apex:column> Apr 18 '16 at 6:17
  • 1
    [check this] (salesforce.stackexchange.com/questions/9924/…) Apr 18 '16 at 6:28

You have List with one radiobutton element for each record. Try to use html :

<apex:pageBlockTable value="{!account.Cases}" var="exscases">

<apex:column headervalue="Cases">
    <input type="radio" name="group" id="{!exscases.Id}" />
  • Hello , now the radio button works as it should work, but now how do I pass the value of selected radio button back to my extension?
    – SfdcBat
    Apr 18 '16 at 6:26
  • Thanks for the input. I used the above approach and it worked. I would like to add how I did it. I just had <input type="radio" name="group" value="{!exscases.Id}" /> and in my controller I had a String radioValue{get;set;}. I used radioValue = apexpages.currentpage().getparameters().get('group'); to get the value of the selected radio button. Having value variable in <input type="radio"...> was important for this approach.
    – SfdcBat
    Apr 18 '16 at 6:54

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.