I have a <apex:pabeBlockTable> which iterates through a custom object and generates checkboxes in two columns for which i am using two custom field of type checkbox. On the click of a checkbox, I want to save value=true for that field in custom object.

<apex:pageblocktable value="{!attlist}" var="a" Width="50%">
     <apex:column width="5%" headerValue="Attendee" id="column1">
         <apex:commandLink value="{!a.Name}" action="{!infoPage}">
            <apex:param value="{!a.id}" assignTo="{!attid}" name="attid" />
    <apex:column width="10%" headerValue="Attendee Pre Survey" id="column2">
          <apex:inputCheckbox value="{!a.SendPreSurvey_Check__c}" selected="true"/>
    <apex:column width="10%" headerValue="Attendee Post Survey" >
           <apex:inputCheckbox value="{!a.SendPostSurvey_Check__c}" selected="false"/>
    <apex:commandButton value="Save" action="{!save}"/>

My controller save() :

public SelectingAttendiesForSurvey(ApexPages.StandardController con){
  visitId= ApexPages.currentPage().getParameters().get('visitid'); 
  attendee=new Attendee__c();
  attlist=[select a.FirstName__c,a.SendPreSurvey_Check__c,a.SendPostSurvey_Check__c,a.Visit__c from  Attendee__c a where a.Visit__c=:visitId ];
public void save()


This is my revised code:

   public void save()
                list<Attendee__c> atlist1=new list<Attendee__c>(); 
                for(Attendee__c a :attlist)
                    if(a.SendPreSurvey__c==true && a.SendPostSurvey__c==true){
                else if(a.SendPreSurvey__c==true && a.SendPostSurvey__c==false) {
                else if(a.SendPostSurvey__c==true && a.SendPreSurvey__c==false) {
                update atlist1;
  • Did you try just public void save() { update attlist; }? – Keith C Oct 16 '14 at 7:54
  • I'm iterating through the attlist and checking each checkbox. Once that checkbox is true I'm adding it in new list and updating it. Thanks @Keith – simmi Oct 16 '14 at 9:39
  • If looks like your save() could have 1 if statement to cover all the cases: if ((a.SendPreSurvey__c == true) || (a.SendPostSurvey__c == true)) – Jeremy Nottingham Oct 16 '14 at 17:06
  • So what's the actual question here? – Jeremy Nottingham Oct 16 '14 at 17:07

use inputField instead of inputCheckbox. For instance:

VF Page

 <apex: pageBlockTable value = "{!attlist}" var = "att" >
      < apex: column headerValue = "abc" >
             <apex: inputField value = "{!att.SendPreSurvey__c}" / > 
      <apex:column headerValue="xyz">
             <apex:inputField value="{!att.SendPostSurvey__c}"/ >
</apex: pageBlockTable > 

Apex Class:

public pagereference save() {
     update attlist;
     return (return to parent page);
|improve this answer|||||
  • Shravan, could you possibly elaborate on your answer and include an example or explain why what you're suggesting will make a difference ? Doing so will enable us to not only solve this issue, but learn why your suggestion solves it. Adding more value will motivate other users to vote on your answer and increase your reputation. – Samuel De Rycke Oct 16 '14 at 15:15
  • Please find code snippet. VF Page <apex:pageBlockTable value="{!attlist}" var="att"> <apex:column headerValue="abc"> <apex:inputField value="{!att.SendPreSurvey__c}"/> </apex:column> <apex:column headerValue="xyz"> <apex:inputField value="{!att.SendPostSurvey__c}"/> </apex:column> </apex:pageBlockTable> Apex Class: public pagereference save() { update attlist; return (return to parent page); } – Shravan Boddula Oct 16 '14 at 16:29
  • Know that you can always update your questions or answers, aim to have all information in your answer rather than the comments. I've gone ahead and updated that for you this time. – Samuel De Rycke Oct 16 '14 at 16:39

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.