You need to sign in to do that
Don't have an account?
fiona gentry
How to write tests that creates sample Case Type Data records, then runs the search and checks if what was returned matches expectations
Dear gurus.
How to write tests that creates sample Case Type Data records, then runs the search and checks if what was returned matches expectations
here is the apex class
Regards,
Fiona
How to write tests that creates sample Case Type Data records, then runs the search and checks if what was returned matches expectations
here is the apex class
public class Stack { @AuraEnabled(cacheable=true) public static List<LookupSearchResult> search(String searchTerm, List<String> selectedIds){ if(String.isBlank(searchTerm) || searchTerm.length() < 2){ return null; } String t = '%' + searchTerm + '%'; // decide how you want to search, "starts with", "includes" or what List<Case_Type_Data__c> records = [SELECT Id, Name, Level_1__c, Level_2__c, Level_3__c FROM Case_Type_Data__c WHERE Level_1__c LIKE :t OR Level_2__c LIKE :t OR Level_3__c LIKE :t ORDER BY Level_1__c, Level_2__c, Level_3__c LIMIT 20]; /* You could also experiment with SOSL? records = [FIND :('*' + searchTerm + '*') IN ALL FIELDS RETURNING Case_Type_Data__c(Id, Name, Level_1__c, Level_2__c, Level_3__c)][0]; */ List<LookupSearchResult> results = new List<LookupSearchResult>(); for(Case_Type_Data__c ctd : records){ results.add(new LookupSearchResult(ctd.Id, 'Case_Type_Data__c', 'standard:case_wrap_up', ctd.Name, String.join(new List<String>{ctd.Level_1__c , ctd.Level_2__c, ctd.Level_3__c}, '; ') )); } return results; } }
Regards,
Fiona
Hi, Fiona gentry,
For your above apex class below is the test class code you can take a look at that for your reference:
myTestDataFactory is used for creating records of Case_Type_Data__c object
If you find this answer helpful to you then mark this as the best answer.
Thanks