Skip to content

Commit 72531c5

Browse files
James SimoneJames Simone
authored andcommitted
issue-16 adding DateLiteralConstant to address issue with passing SOQL date literals as strings
1 parent 073c2b7 commit 72531c5

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

src/classes/SOQLUtils.cls

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ public without sharing class SOQLUtils {
88

99
public static String toSOQLString(Object value) {
1010
if(value == null) return null;
11+
else if(value instanceof DateLiteralConstant) {
12+
DateLiteralConstant dateLiteral = (DateLiteralConstant) value;
13+
return dateLiteral.value;
14+
}
1115
else if(value instanceof Boolean) return String.valueOf((Boolean)value);
1216
else if(value instanceof Date) return String.valueOf((Date)value);
1317
else if(value instanceof Datetime) {

src/classes/TaskRepository.cls

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ public without sharing class TaskRepository extends SObjectRepository {
66
super(TaskRepository.DEFAULT_FIELD_SET);
77
}
88

9+
public TaskRepository(Boolean returnCommonFields) {
10+
super(TaskRepository.DEFAULT_FIELD_SET,returnCommonFields);
11+
}
12+
913
public Task getRecord(Id taskId) {
1014
return (Task)this
1115
.whereIdEquals(taskId)
@@ -26,8 +30,7 @@ public without sharing class TaskRepository extends SObjectRepository {
2630

2731
public List<Task> getListOfCreatedSinceLastWeek() {
2832
return (List<Task>)this
29-
.whereFieldGreaterThanOrEqualTo(Schema.Lead.CreatedDate, 'LAST_WEEK')
30-
.setAsUpdate()
33+
.whereFieldGreaterThanOrEqualTo(Schema.Lead.CreatedDate, new DateLiteralConstant().LAST_WEEK)
3134
.getQueryResults();
3235
}
3336

@@ -40,6 +43,15 @@ public without sharing class TaskRepository extends SObjectRepository {
4043
.getQueryResults();
4144
}
4245

46+
public List<Task> getListByFieldForWhoIds(Schema.SObjectField field, String value, List<Id> whoIdList) {
47+
return (List<Task>)this
48+
.whereWhoIdIn(whoIdList)
49+
.whereFieldEquals(field,value)
50+
.orderBy(Schema.Task.WhoId)
51+
.orderBy(Schema.Task.CreatedDate, SObjectRepository.SortOrder.DESCENDING)
52+
.getQueryResults();
53+
}
54+
4355
public List<Task> searchInAllFields(String searchTerm) {
4456
return (List<Task>)this
4557
.whereIsClosed(false)

src/classes/TaskRepository_Tests.cls

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private class TaskRepository_Tests {
2626
}
2727

2828
@isTest
29-
static void getRecord() {
29+
static void it_should_return_specific_tasks_by_Id() {
3030
Task expectedTask = [SELECT Id FROM Task LIMIT 1];
3131

3232
Test.startTest();
@@ -38,7 +38,7 @@ private class TaskRepository_Tests {
3838
}
3939

4040
@isTest
41-
static void getList() {
41+
static void it_should_return_tasks_by_list() {
4242
List<Task> expectedTaskList = [SELECT Id FROM Task];
4343
List<Id> expectedTaskIdList = new List<Id>(new Map<Id, Task>(expectedTaskList).keySet());
4444

@@ -51,7 +51,7 @@ private class TaskRepository_Tests {
5151
}
5252

5353
@isTest
54-
static void getListOfOpenForWhoId() {
54+
static void it_should_return_all_open_tasks_by_who_Id() {
5555
Lead lead = [SELECT Id FROM Lead LIMIT 1];
5656

5757
Map<Id, Task> expectedTaskMap = new Map<Id, Task>([SELECT Id, WhoId FROM Task WHERE WhoId = :lead.Id AND IsClosed = false]);
@@ -70,6 +70,24 @@ private class TaskRepository_Tests {
7070

7171
@isTest
7272
static void searchInAllFields() {
73+
@isTest
74+
static void it_should_not_return_a_task_created_more_than_two_weeks_ago_when_querying_for_last_week() {
75+
Lead lead = [SELECT Id FROM Lead LIMIT 1];
76+
77+
Task task = TestDataGenerator.createCommunicationTask(lead.Id, null);
78+
task.CreatedDate = (Datetime)System.today().addDays(-15);
79+
80+
Test.startTest();
81+
Map<Id, Task> returnedTaskMap = new Map<Id,Task>(new TaskRepository().getListOfCreatedSinceLastWeek());
82+
Test.stopTest();
83+
84+
for(Task tsk : returnedTaskMap.values()) {
85+
System.assertEquals(false,returnedTaskMap.containsKey(task.Id));
86+
}
87+
}
88+
89+
@isTest
90+
static void it_should_return_appropriate_tasks_when_querying_with_SOSL() {
7391
String searchTerm = 'thing';
7492
List<Task> expectedTaskList = (List<Task>)[FIND :searchTerm IN ALL FIELDS RETURNING Task(Id WHERE IsClosed = false)][0];
7593

0 commit comments

Comments
 (0)