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
Ravi PrabhuRavi Prabhu 

Check box value not passing to controller from visualforce page

Hi,
This looks to be simple but not able to find the issue.
I have a visualforce page with a pageblock. The page block displays 2 fields. One is date and other field is name from drop down. User should select these 2 fields and then click 'Go' button which will display the records. Later user can select the records and delete it (need to select multiple records using checkbox). The 'Go' button is working and display records but delete button is not working after selecting the records.
Please help.
Visualforce page:
    <apex:form id="formId" styleClass="myFormStyle" >
	<apex:actionRegion >    
        <apex:pageBlock id="pgblock2" title="Summary"   >
        <apex:pageBlockSection id="pgblocksection2">
 		<apex:OutputPanel >
	         <apex:panelGrid columns="7">
        	     <apex:outputLabel style="font-style:regular; font-weight:bold; 
			    font-size:11px; font-family:Helvetica;" >Date </apex:outputLabel>
             		<apex:inputText id="Date" value="{!SelectedDate}" onfocus="DynamicDatePicker(this);" 
					onchange="checkDateFormatt(this.id);" 
					size="10" disabled="false" style="width:90px; margin-right:10px;"  />
		              <apex:param value="{!SelectedDate}" assignTo="{!selectedDate}" name="p1"/>
	             <apex:outputLabel style="font-style:regular; font-weight:bold; font-size:11px; font-family:Helvetica;" >
                                      Select Assigned Person </apex:outputLabel>
	        	     <apex:selectList id="selectedlist" value="{!selectedUserId}" size="1" multiselect="false" >
        	        	      <apex:param value="{!selectedUserId}" assignTo="{!selectedUserId}" name="p2"/>
               			      <apex:selectOptions value="{!ListOfUser}" />
		             </apex:selectList>
             
            	    <apex:commandButton id="Go" action="{!getsummarylist}" value="Go"  
				onclick="validatechk();"  rerender="msgsS" />
	        </apex:panelGrid>           
             </apex:OutputPanel>
         </apex:pageBlockSection>

	<apex:pageBlockButtons location="Bottom" >
        	<apex:commandButton id="deleteit" value="Delete" 
			action="{!delete_now}"  reRender="msgsS"/>
	</apex:pageBlockButtons>   
      
        <apex:outputPanel id="panelId">
	   <apex:pageBlockTable value="{!sub}" var="I"  id="msgsS" >
             <apex:column headerValue="Select" >
          		<apex:inputCheckbox  value="{!I.checked}" />
                   <apex:param assignTo="{!I.checked}" value="{!I.checked}" />
             </apex:column>
             <apex:column headervalue="Date"  value="{!I.tkt.Date__c}"/>
             <apex:column headervalue="Ticket Number" value="{!I.tkt.Ticket_Number__c}"/>
             <apex:column headervalue="Division"  value="{!I.tkt.Division__c}"/>
             <apex:column headervalue="Application"  value="{!I.tkt.Application__c}"/>
             <apex:column headervalue="Responsible"  value="{!I.tkt.Responsible__c}"/>
             <apex:column headervalue="Effort"  value="{!I.tkt.Effort__c}"/>
        </apex:pageBlockTable>
        </apex:outputPanel>
       </apex:pageBlock>   
        
        </apex:actionRegion>
    </apex:form>
</apex:page>

Apex controller
public with sharing class TestPageBlock2Cont {
    public String selecteduserId {get;set;}
    public Date selectedDate {get;set;}
    List<SelectOption> selectOptions{get;set;}
    
    public List<Wrapperclass> sub {get;set;}

    public TestPageBlock2Cont() {
        
  	     	 tktRecord = new Ticket_Effort_Category__c(); 
   			  lstwrapper = new list<wrapper>();
        	  header = 'Date,Division\r\n';
 	}
    
 //after pressing 'Go' button, this method will be called  
    public Pagereference getsummarylist(){
         if(selectedDate == null){
             system.debug('selectedDate 3 = ' +selectedDate);
          ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please enter date'));
         }
        else{
	        sub = new List<WrapperClass>(); 
 		list<ticket_effort_category__c> fetchList = new list<ticket_effort_category__c>();
        	fetchList = [select id, Date__c, ticket_number__c, Division__c, 
					Application__c, 
					Responsible__c, Effort__c 
	                    from Ticket_Effort_Category__c 
	                     where Responsible__c = :selectedUserId and Date__c = :selectedDate];
        		for(Ticket_Effort_Category__c cr : fetchlist){	
			sub.add(new wrapperClass (cr,false));
                                             }
  		}
           return null;
    }       
    
//wrapp the records and checkbox
  public class WrapperClass {
        public Ticket_effort_category__c tkt {get; set;}
	public Boolean checked {get; set;}
	public wrapperClass(Ticket_effort_category__c tkt, Boolean checked){
        this.tkt=tkt;
        this.checked = checked;
    }
    }
//delete the selected records        
  public void delete_now(){
       List<Ticket_Effort_Category__c> del = new list<Ticket_Effort_Category__c>();
        for(WrapperClass cc: sub){
            system.debug('tktid = ' +tktid);
            if(cc.checked == true){
                
                del.add(cc.tkt);
            }
        }
 		delete del;  
        return null;
    }

//show up the dropdown for user to select the name   
    public List<SelectOption> getListOfUser(){
 		 
         selectOptions = new List<SelectOption>();
         selectOptions.add(new SelectOption( ' ' ,'---Select---'));
     	 Schema.DescribeFieldResult describeResult = Ticket_Effort_Category__c.Responsible__c.getDescribe();
      	List<Schema.PicklistEntry> pickListEntries = describeResult.getPicklistValues();
            
      	for( Schema.PicklistEntry eachEntry : pickListEntries) {
         selectOptions.add(new SelectOption(eachEntry.getLabel(), eachEntry.getValue()));    
      	}
        return selectOptions;
        
	}
}

 
ANUTEJANUTEJ (Salesforce Developers) 
Hi Ravi,

Have you tried checking if the accounts are being selected properly and if the delete button is actually working?

Please check and let us know, looking forward to your response.

Regards,
Anutej
Ravi PrabhuRavi Prabhu
Hi Antej, When I click on delete button, the delete_now method is called and displays (system.debug) the records from wrapper class but the "checked" (check box) value shows as false. The value of check box is not passing to Apex controller even though i have used <apex:param>. 

User-added image
ANUTEJANUTEJ (Salesforce Developers) 
So I tried to implement a similar scenario and I was using the code from https://www.infallibletechie.com/2014/08/deleting-checked-rows-using-apex-in.html to see if it works, and I was able to get it working can you try checking this code once?
Dushyant SonwarDushyant Sonwar
This is occuring due to actionRegion , I did some changes in your code .
 
Visualforce page:
    <apex:form id="formId" styleClass="myFormStyle" >
	
        <apex:pageBlock id="pgblock2" title="Summary"   >
		<apex:pageMessages id="pg" />
		<apex:actionRegion >    
        <apex:pageBlockSection id="pgblocksection2">
 		<apex:OutputPanel >
	         <apex:panelGrid columns="7">
        	     <apex:outputLabel style="font-style:regular; font-weight:bold; 
			    font-size:11px; font-family:Helvetica;" >Date </apex:outputLabel>
             		<apex:inputText id="Date" value="{!SelectedDate}" onfocus="DynamicDatePicker(this);" 
					onchange="checkDateFormatt(this.id);" 
					size="10" disabled="false" style="width:90px; margin-right:10px;"  />
		              <apex:param value="{!SelectedDate}" assignTo="{!selectedDate}" name="p1"/>
	             <apex:outputLabel style="font-style:regular; font-weight:bold; font-size:11px; font-family:Helvetica;" >
                                      Select Assigned Person </apex:outputLabel>
	        	     <apex:selectList id="selectedlist" value="{!selectedUserId}" size="1" multiselect="false" >
        	        	      <apex:param value="{!selectedUserId}" assignTo="{!selectedUserId}" name="p2"/>
               			      <apex:selectOptions value="{!ListOfUser}" />
		             </apex:selectList>
             
            	    <apex:commandButton id="Go" action="{!getsummarylist}" value="Go"  
				onclick="validatechk();"  rerender="msgsS" />
	        </apex:panelGrid>           
             </apex:OutputPanel>
         </apex:pageBlockSection>
		</apex:actionRegion>
		
	<apex:pageBlockButtons location="Bottom" >
        	<apex:commandButton id="deleteit" value="Delete" 
			action="{!delete_now}"  reRender="msgsS,pg"/>
	</apex:pageBlockButtons>   
      
        <apex:outputPanel id="panelId">
	   <apex:pageBlockTable value="{!sub}" var="I"  id="msgsS" >
             <apex:column headerValue="Select" >
          		<apex:inputCheckbox  value="{!I.checked}" />
                   <apex:param assignTo="{!I.checked}" value="{!I.checked}" />
             </apex:column>
             <apex:column headervalue="Date"  value="{!I.tkt.Date__c}"/>
             <apex:column headervalue="Ticket Number" value="{!I.tkt.Ticket_Number__c}"/>
             <apex:column headervalue="Division"  value="{!I.tkt.Division__c}"/>
             <apex:column headervalue="Application"  value="{!I.tkt.Application__c}"/>
             <apex:column headervalue="Responsible"  value="{!I.tkt.Responsible__c}"/>
             <apex:column headervalue="Effort"  value="{!I.tkt.Effort__c}"/>
        </apex:pageBlockTable>
        </apex:outputPanel>
       </apex:pageBlock>   
        
        
    </apex:form>
</apex:page>

Apex controller
public with sharing class TestPageBlock2Cont {
    public String selecteduserId {get;set;}
    public Date selectedDate {get;set;}
    List<SelectOption> selectOptions{get;set;}
    
    public List<Wrapperclass> sub {get;set;}

    public TestPageBlock2Cont() {
        
  	     	 tktRecord = new Ticket_Effort_Category__c(); 
   			  lstwrapper = new list<wrapper>();
        	  header = 'Date,Division\r\n';
 	}
    
 //after pressing 'Go' button, this method will be called  
    public Pagereference getsummarylist(){
         if(selectedDate == null){
             system.debug('selectedDate 3 = ' +selectedDate);
          ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please enter date'));
         }
        else{
	        sub = new List<WrapperClass>(); 
 		list<ticket_effort_category__c> fetchList = new list<ticket_effort_category__c>();
        	fetchList = [select id, Date__c, ticket_number__c, Division__c, 
					Application__c, 
					Responsible__c, Effort__c 
	                    from Ticket_Effort_Category__c 
	                     where Responsible__c = :selectedUserId and Date__c = :selectedDate];
        		for(Ticket_Effort_Category__c cr : fetchlist){	
			sub.add(new wrapperClass (cr,false));
                                             }
  		}
           return null;
    }       
    
//wrapp the records and checkbox
  public class WrapperClass {
        public Ticket_effort_category__c tkt {get; set;}
	public Boolean checked {get; set;}
	public wrapperClass(Ticket_effort_category__c tkt, Boolean checked){
        this.tkt=tkt;
        this.checked = checked;
    }
    }
//delete the selected records        
  public void delete_now(){
       List<Ticket_Effort_Category__c> del = new list<Ticket_Effort_Category__c>();
        for(WrapperClass cc: sub){
            system.debug('tktid = ' +tktid);
            if(cc.checked == true){
                
                del.add(cc.tkt);
            }
        }
 		delete del;  
		getsummarylist();
        return null;
    }

//show up the dropdown for user to select the name   
    public List<SelectOption> getListOfUser(){
 		 
         selectOptions = new List<SelectOption>();
         selectOptions.add(new SelectOption( ' ' ,'---Select---'));
     	 Schema.DescribeFieldResult describeResult = Ticket_Effort_Category__c.Responsible__c.getDescribe();
      	List<Schema.PicklistEntry> pickListEntries = describeResult.getPicklistValues();
            
      	for( Schema.PicklistEntry eachEntry : pickListEntries) {
         selectOptions.add(new SelectOption(eachEntry.getLabel(), eachEntry.getValue()));    
      	}
        return selectOptions;
        
	}
}

This will work for sure.
Dushyant SonwarDushyant Sonwar
Ravi,

Did you try with above solution? Does it solve your purpose?