You need to sign in to do that
Don't have an account?

pageBlockTable change depending on selectlist value
Hi. I want to create a selectlist exactly like this.
I created the logic for this but I really don't know how to make it with Visualforce.
Controller:
public class TaskController { public List<Task> lstTasksForUser {get;set;} public TaskController(){ lstTasksForUser = [Select id, ActivityDate, Status, Subject, WhoId, WhatId, CompanyName__c, AccountId From Task WHERE Status!= 'Completed' AND OwnerId =: UserInfo.getUserId()]; } public List<Task> tasksToday {get;set;} public List<Task> getTodayTasks(){ tasksToday = [Select id, CreatedDate, ActivityDate, Status, Subject, WhoId, WhatId, CompanyName__c, AccountId From Task where ActivityDate = TODAY AND Status!= 'Completed']; return tasksToday; } public List<Task> tasksThisMonth {get;set;} public List<Task> getThisMonthTasks(){ tasksThisMonth = [Select id, CreatedDate, ActivityDate, Status, Subject, WhoId, WhatId, CompanyName__c, AccountId From Task where ActivityDate = THIS_MONTH AND Status!= 'Completed']; return tasksThisMonth; } public List<Task> tasksCloseTomorow {get;set;} public List<Task> getTomorowCloseTasks(){ tasksCloseTomorow = [Select id, CreatedDate, ActivityDate, Status, Subject, WhoId, WhatId, CompanyName__c, AccountId From Task where ActivityDate = TOMORROW AND Status!= 'Completed']; return tasksCloseTomorow; } public List<Task> tasksOverdue {get;set;} public List<Task> getOverdueTasks(){ tasksOverdue = [Select id, CreatedDate, ActivityDate, Status, Subject, WhoId, WhatId, CompanyName__c, AccountId From Task where ActivityDate < TODAY AND Status!= 'Completed' ]; return tasksOverdue; } }
This is my VF page and I'm stuck on this selectList part. I want when I select Today in the selectListOptions my pageBlockTable to change and fetch the records for Today.
<apex:page controller="TaskController" tabStyle="Task"> <apex:form > <apex:pageBlock title="My Tasks" id="tasks_list"> <apex:pageBlockTable value="{!lstTasksForUser}" var="tsk"> <apex:selectList size="5" onchange> <apex:selectOptions value="{!TodayTasks}" > </apex:selectOptions> </apex:selectList> <apex:column headerValue="Complete" > <a href="https://eu12.salesforce.com/{!tsk.id}/e?close=1&retURL=%2Fhome%2Fhome.jsp" rendered="{!if(tsk.status!='Completed',true,false)}" > X </a> </apex:column> <apex:column value="{!tsk.ActivityDate}"/> <apex:column value="{!tsk.Status}"/> <apex:column value="{!tsk.Subject}"/> <apex:column value="{!tsk.WhoId}"/> <apex:column value="{!tsk.WhatId}"/> <apex:column value="{!tsk.CompanyName__c}"/> <apex:column value="{!tsk.AccountId}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
Use this code.
All Answers
Please check this. I didn't test this. Let me know if you face any issues.
I have a bunch of errors. in Line 7, 13,14,15,16,17,18,19,20,25,27 in Controller.
Why you did delete my logic? It was not good? I wrote the logic to fetch the records for today, this month, tomorrow, overdue
Errors is: The method does not exist or incorrect signature: void add(String, String) from the type List<System.SelectOption>
From line 11 to 20 iI have this error. Do you know why?
And the last two errors. Invalid bind expression type of String for column of type Date and Unknown property 'TaskController.selFilter'
Use this code.
Task tsk = new Task();
tsk.Subject = 'Activity';
tsk.ActivityDate = System.today();
tsk.Status = 'Completed';
tsk.Priority ='Normal';
tsk.Description = 'Test';
insert tsk;
Basically, I only created the task, and now I'm stuck. I don't know how can I cover the code Coverage on my class Task Controller.
I'm confused about how can i test this method and make the code coverage for class.