-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the metho SObjectRepository.getSearchQuery(String searchTerm, SObjectRepository.SearchGroup searchGroup); Made several private methods to build to the individual components. getQuery and getSearchQuery methods call these methods where needed to build each type of query string Added new enum, SObjectRepository.SearchGroup. This is used to control what fields are searched for SOSL queries Added ISObjectRespository.List<SObject> searchInAllFields(String searchTerm); to require one basic SOSL method per object Renamed/tweaked some existing methods Added some missing & new test classes/methods
- Loading branch information
Showing
7 changed files
with
188 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
public interface ISObjectRepository { | ||
|
||
// SOQL | ||
SObject getRecord(Id recordId); | ||
List<SObject> getList(List<Id> recordIdList); | ||
// SOSL | ||
List<SObject> searchInAllFields(String searchTerm); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
@isTest | ||
private class TaskRepository_Tests { | ||
|
||
@testSetup | ||
static void setup() { | ||
List<Lead> leadList = new List<Lead>(); | ||
for(Integer i = 0; i < 5; i++) { | ||
Lead lead = new Lead( | ||
Company = 'My Test Company', | ||
LastName = 'Gillespie' | ||
); | ||
leadList.add(lead); | ||
} | ||
insert leadList; | ||
|
||
List<Task> taskList = new List<Task>(); | ||
for(Lead lead : leadList) { | ||
Task task = new Task( | ||
Description = 'Call about the thing', | ||
Status = 'Not Started', | ||
WhoId = lead.Id | ||
); | ||
taskList.add(task); | ||
} | ||
insert taskList; | ||
} | ||
|
||
@isTest | ||
static void getRecord() { | ||
Task expectedTask = [SELECT Id FROM Task LIMIT 1]; | ||
|
||
Test.startTest(); | ||
|
||
Task returnedTask = new TaskRepository().getRecord(expectedTask.Id); | ||
System.assertEquals(expectedTask.Id, returnedTask.Id); | ||
|
||
Test.stopTest(); | ||
} | ||
|
||
@isTest | ||
static void getList() { | ||
List<Task> expectedTaskList = [SELECT Id FROM Task]; | ||
List<Id> expectedTaskIdList = new List<Id>(new Map<Id, Task>(expectedTaskList).keySet()); | ||
|
||
Test.startTest(); | ||
|
||
List<Task> returnedTaskList = new TaskRepository().getList(expectedTaskIdList); | ||
System.assertEquals(expectedTaskList.size(), returnedTaskList.size()); | ||
|
||
Test.stopTest(); | ||
} | ||
|
||
@isTest | ||
static void getListOfOpenForWhoId() { | ||
Lead lead = [SELECT Id FROM Lead LIMIT 1]; | ||
|
||
Map<Id, Task> expectedTaskMap = new Map<Id, Task>([SELECT Id, WhoId FROM Task WHERE WhoId = :lead.Id AND IsClosed = false]); | ||
System.assert(expectedTaskMap.size() > 0); | ||
|
||
Test.startTest(); | ||
|
||
Map<Id, Task> returnedTaskMap = new Map<Id, Task>(new TaskRepository().getListOfOpenForWhoId(lead.Id)); | ||
System.assertEquals(returnedTaskMap.size(), returnedTaskMap.size()); | ||
for(Id expectedTaskId : expectedTaskMap.keySet()) { | ||
System.assert(returnedTaskMap.containsKey(expectedTaskId)); | ||
} | ||
|
||
Test.stopTest(); | ||
} | ||
|
||
@isTest | ||
static void searchInAllFields() { | ||
String searchTerm = 'thing'; | ||
List<Task> expectedTaskList = (List<Task>)[FIND :searchTerm IN ALL FIELDS RETURNING Task(Id WHERE IsClosed = false)][0]; | ||
|
||
Test.startTest(); | ||
|
||
List<Task> returnedTaskList = new TaskRepository().searchInAllFields(searchTerm); | ||
System.assertEquals(expectedTaskList.size(), returnedTaskList.size()); | ||
|
||
Test.stopTest(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>38.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |