|
| 1 | +public without sharing class TaskQueryRepository { |
| 2 | + |
| 3 | + // This class largely follows the same pattern as LeadQueryRepository.cls |
| 4 | + // For more information on how these classes should work, refer to the lead class |
| 5 | + // The main difference in this class is the inclusion of the getTasksByWhoId methods |
| 6 | + // Even though you may want to get all tasks for a lead, the query to handle |
| 7 | + // querying for those records should live in this class since ultimately |
| 8 | + // they are task records, so they fall under the TaskQueryRepository's domain |
| 9 | + |
| 10 | + public static Task getTaskById(Id taskid) { |
| 11 | + return getTasksById(new Set<Id>{taskid})[0]; |
| 12 | + } |
| 13 | + |
| 14 | + public static List<Task> getTasksById(List<Task> taskList) { |
| 15 | + return getTasksById(new Map<Id, Task>(taskList).keySet()); |
| 16 | + } |
| 17 | + |
| 18 | + public static List<Task> getTasksById(List<Id> taskIdSet) { |
| 19 | + return getTasksById(new Set<Id>(taskIdSet)); |
| 20 | + } |
| 21 | + |
| 22 | + public static List<Task> getTasksById(Map<Id, Task> taskMap) { |
| 23 | + return getTasksById(taskMap.keySet()); |
| 24 | + } |
| 25 | + |
| 26 | + public static List<Task> getTasksById(Set<Id> taskIdSet) { |
| 27 | + String whereClause = 'WHERE ' + Schema.Task.Id + ' IN :taskIdSet'; |
| 28 | + String query = new QueryGenerator(SObjectType.Task.FieldSets.MyFieldSet).buildQuery(whereClause); |
| 29 | + |
| 30 | + return (List<Task>)Database.query(query); |
| 31 | + } |
| 32 | + |
| 33 | + public static List<Task> getTasksByWhoId(Id whoId) { |
| 34 | + return getTasksByWhoIds(new List<Id>{whoId}); |
| 35 | + } |
| 36 | + |
| 37 | + public static List<Task> getTasksByWhoIds(List<Id> whoIdList) { |
| 38 | + String whereClause = 'WHERE ' + Schema.Task.WhoId + ' IN :whoIdList'; |
| 39 | + String query = new QueryGenerator(SObjectType.Task.FieldSets.MyFieldSet).buildQuery(whereClause); |
| 40 | + |
| 41 | + return (List<Task>)Database.query(query); |
| 42 | + } |
| 43 | + |
| 44 | +} |
0 commit comments