forked from SalesforceSFDC/Apex-Classes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PagingTasksController.class
102 lines (81 loc) · 2.75 KB
/
PagingTasksController.class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
public class PagingTasksController{
public List<Task> tasks;
public Integer CountTotalRecords{get;set;}
public String QueryString {get;set;}
public Integer OffsetSize = 0;
private Integer QueryLimit = 3;
public List<Task> lstTasks;
public String searchText {get;set;}
public string sortField = 'Subject'; // default sort column
private string sApplySOQL = '';
// the current sort direction. defaults to ascending
public String sortDir {
get { if (sortDir == null) { sortDir = 'asc'; } return sortDir; }
set;
}
// the current field to sort by. defaults to role name
public String getsortField() {
return sortField;
}
// the current field to sort by.
public void setsortField(string value) {
sortField = value;
}
// toggles the sorting of query from asc<-->desc
public void toggleSort() {
// simply toggle the direction
sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
integer iIndex = sApplySOQL.indexOf('Order By');
if (iIndex > -1){
sApplySOQL = sApplySOQL.substringBefore('Order By');
sApplySOQL = sApplySOQL + ' Order By ' + sortField + ' ' + sortDir;
}
tasks = Database.query(sApplySOQL );
}
public PagingTasksController (){
//CountTotalRecords= [select count() from Task];
}
public List<Task> getTasks(){
if(tasks == null){
tasks = new List<Task>();
}
return tasks;
}
public void findTasks(){
String qStr2 = 'Select count() from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\'';
CountTotalRecords = Database.countQuery(qStr2);
queryTasks();
}
public void queryTasks(){
String qStr = 'Select OwnerId,Subject,Status,Priority from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\' Order By Subject,Status limit ' + QueryLimit + ' offset ' + OffsetSize;
sApplySOQL = qStr;
tasks = Database.query(sApplySOQL );
//tasks.sort();
}
public Boolean getDisablePrevious(){
if(OffsetSize>0){
return false;
}
else return true;
}
public Boolean getDisableNext() {
if (OffsetSize + QueryLimit < countTotalRecords){
return false;
}
else return true;
}
public PageReference Next() {
OffsetSize += QueryLimit;
queryTasks();
return null;
}
public PageReference Previous() {
OffsetSize -= QueryLimit;
queryTasks();
return null;
}
public PageReference save() {
update tasks;
return ApexPages.CurrentPage();
}
}