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
Gaurav Gulanjkar 18Gaurav Gulanjkar 18 

Inputcheck box select/refresh data

Hi All,

I have a requirement where I need to show task list of a case on visualforce page with checkbox's for each task. When I select the tasks, On select of the check box I need to update the task status in the database and refresh the table back on the visualforce page. I have written the logic to display the task list on the VF. How can I update the database on select of the checkbox and refresh the page.

Controller:
public class RelatedTaskController {
    public List<taskWrapper> taskList {get; set;}
    
    public RelatedTaskController(){
        getTasks();
    }

	public List<taskWrapper> getTasks() {
		if(taskList == null) {
			taskList = new List<taskWrapper>();
			for(Task c: [select Id, Owner.Name,Status,Subject from Task where WhatId =: '5008E000001EOg6QAG']) {
				taskList.add(new taskWrapper(c));
			}
		}
		return taskList;
	}
	
         public class taskWrapper {
		public Task tsk {get; set;}
		public Boolean selected {get; set;}

		public taskWrapper(Task t) {
			tsk = t;
			selected = false;
		}
	}
}


Visualforce page:
<apex:page controller="RelatedTaskController">
    <apex:form >
        <apex:pageBlock >
           <apex:pageBlockTable value="{!taskList}" var="t" id="table">
                <apex:column >
                    <apex:inputCheckbox value="{!t.selected}"/>
                </apex:column>
                <apex:column value="{!t.tsk.Owner.Name}" />
                <apex:column value="{!t.tsk.Subject}" />
                <apex:column value="{!t.tsk.Status}" />
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Thanks,
Gaurav

 
Martijn SchwarzerMartijn Schwarzer
Hi Gaurav,

You will need to add an on-change event to your inputCheckbox that will call an Apex Controller method which will handle your logic. Also, you can rerender the table. It works like this:
 
<apex:inputCheckbox value="{!t.selected}">
    <apex:actionSupport event="onchange" action="{!yourApexControllerMethodName}" rerender="table">
        <!-- Apex method parameters are added like this: -->
        <apex:param name="accountId" value="{!account.Id}"/>
    </apex:actionSupport>
</apex:inputCheckbox>

Hope this helps!

Happy coding!

Best regards,
Martijn Schwärzer