0

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:commandLink>
     </apex:column>
    <apex:column width="10%" headerValue="Attendee Pre Survey" id="column2">
          <apex:inputCheckbox value="{!a.SendPreSurvey_Check__c}" selected="true"/>
    </apex:column>
    <apex:column width="10%" headerValue="Attendee Post Survey" >
           <apex:inputCheckbox value="{!a.SendPostSurvey_Check__c}" selected="false"/>
    </apex:column> 
    </apex:pageblocktable> 
</apex:pageBlock> 
<center>
    <apex:commandButton value="Save" action="{!save}"/>
</center>

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()
        {
            if(attlist[0].SendPreSurvey_Check__c==true){
                attlist[0].SendPreSurvey_Check__c=true;
            } 
           else{
                attlist[0].sendPreSurvet_Check=false;
                }
}

EDIT

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){
                     atlist1.add(a); 
                 }
                else if(a.SendPreSurvey__c==true && a.SendPostSurvey__c==false) {
                    atlist1.add(a); 
                }
                else if(a.SendPostSurvey__c==true && a.SendPreSurvey__c==false) {
                    atlist1.add(a); 
                 }
                }
                update atlist1;
              }  
4
  • Did you try just public void save() { update attlist; }?
    – Keith C
    Oct 16, 2014 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, 2014 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)) Oct 16, 2014 at 17:06
  • So what's the actual question here? Oct 16, 2014 at 17:07

1 Answer 1

-1

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>
      <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);
 }
3
  • 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. Oct 16, 2014 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); }
    – S B
    Oct 16, 2014 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. Oct 16, 2014 at 16:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .