Created
September 25, 2014 10:39
-
-
Save pchittum/bfad7380b97f33c43b2e to your computer and use it in GitHub Desktop.
SOSL and Testing for SOSL in Apex
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
public PageReference doSearch() { | |
results = (List<Candidate__c>)[FIND :searchText IN ALL FIELDS RETURNING Candidate__c(Id, First_Name__c, Last_Name__c, Email__c, City__c, State_Province__c, Phone__c)] [0]; | |
return null; | |
} | |
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
Candidate__c cand = new Candidate__c(first_name__c = 'Sammy', last_name__c = 'Bakersfield', email__c ='s@bakersfield.com'); | |
insert cand; | |
// the following 3 lines are special; for testing SOSL in testMethods | |
// see the Apex PDF for more info on SOSL in testMethods | |
Id [] fixedSearchResults = new Id[] {cand.id}; | |
Test.setFixedSearchResults(fixedSearchResults); | |
// now we do the controller's sosl search | |
extension.doSearch(); | |
// verify the results of the search | |
List<Candidate__c> results = extension.results; | |
System.debug('results=' + results); | |
System.assert(results.size() > 0); | |
System.assertNotEquals(results[0].email__c,null); | |
System.assertEquals(results[0].last_name__c,cand.last_name__c); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment