fork download
  1. public class ToDoListController {
  2.  
  3. public List<TaskWrapper> tasks {get; set;}
  4. public String newTaskSubject {get; set;}
  5.  
  6. public ToDoListController() {
  7. tasks = new List<TaskWrapper>();
  8. loadTasks();
  9. }
  10.  
  11. private void loadTasks() {
  12. tasks.clear();
  13. for (Task t : [SELECT Id, Subject, Status, ActivityDate FROM Task WHERE WhoId = :UserInfo.getUserId() ORDER BY ActivityDate ASC NULLS FIRST]) { // Filter tasks for current user
  14. tasks.add(new TaskWrapper(t));
  15. }
  16. }
  17.  
  18. public PageReference addTask() {
  19. if (String.isBlank(newTaskSubject)) {
  20. ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Task subject cannot be empty.'));
  21. return null;
  22. }
  23.  
  24. Task newTask = new Task(Subject = newTaskSubject, WhoId = UserInfo.getUserId()); // Assign the task to the current user
  25. try {
  26. insert newTask;
  27. newTaskSubject = ''; // Clear the input field
  28. loadTasks(); // Refresh the task list
  29. } catch (Exception ex) {
  30. ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Error creating task: ' + ex.getMessage()));
  31. }
  32. return null;
  33. }
  34.  
  35. public PageReference toggleTaskStatus() {
  36. List<Task> tasksToUpdate = new List<Task>();
  37. for (TaskWrapper tw : tasks) {
  38. if (tw.isSelected) {
  39. tw.task.Status = (tw.task.Status == 'Completed') ? 'Not Started' : 'Completed';
  40. tasksToUpdate.add(tw.task);
  41. }
  42. }
  43.  
  44. try {
  45. update tasksToUpdate;
  46. loadTasks();
  47. } catch (Exception ex) {
  48. ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Error updating tasks: ' + ex.getMessage()));
  49. }
  50. return null;
  51. }
  52.  
  53. public class TaskWrapper {
  54. public Task task {get; set;}
  55. public Boolean isSelected {get; set;}
  56.  
  57. public TaskWrapper(Task t) {
  58. task = t;
  59. isSelected = false;
  60. }
  61. }
  62. }
Success #stdin #stdout #stderr 0.01s 9012KB
stdin
Standard input is empty
stdout
Object: UndefinedObject error: did not understand #ToDoListController
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject class(Object)>>doesNotUnderstand: #ToDoListController (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:1)
stderr
./prog:3: parse error, expected '}'