If you do not want the query to return an empty list of results, you can use the Test.setFixedSearchResults system method to define a list of record IDs that are returned by the search.
Apex Class:
Apex Class:
- public class SOSLController
- {
- public static void findMatchingData(String str)
- {
- List<List<Sobject>> searchList = [FIND :str RETURNING Account(Id, Name), Lead];
- List<Account> accounts = ((List<Account>)searchList[0]);
- if(accounts.size() > 0)
- {
- for(Account currAcc : accounts)
- {
- // do your logic.
- }
- }
- }
- }
Test Class:
- @isTest
- private class TestSOSLController
- {
- static testMethod void insertAccount()
- {
- Account acc = new Account();
- acc.Name = 'Test Account';
- insert acc;
- Id [] fixedSearchResults= new Id[1];
- fixedSearchResults[0] = acc.Id;
- Test.setFixedSearchResults(fixedSearchResults);
- SOSLController.findMatchingData('Test');
- }
- }
Step 1: Create a record that you want to return in a search result.
Step 2: Create a list and assign the inserted id.
Step 3: Use standard method Test.setFixedSearchResults and pass the above ID list.
Step 4: Call your apex method to test your functionality.
Cloud servers are the best in safe guarding one's information thorugh online. Without this dedicated methodology many companies would have not existed at all. The same though has been furnished above. Thanks for sharing this worth while content in here. Keep writing article like this.
ReplyDeleteSalesforce certification Training in Chennai | Salesforce developer training in chennai
Why don't you try creating a record that doesn't contain your search term 'Test'. You will find that it is still returned in the search results, which isn't very useful...
ReplyDeleteGreat!it is really nice blog information.after a long time i have grow through such kind of ideas.
ReplyDeletethanks for share your thoughts with us.
german learning classes in bangalore
german coaching classes in bangalore
German Training in Nolambur
German Training in Saidapet
ReplyDeleteHi,
I must appreciate you for providing such a valuable content for us. This is one amazing piece of article. Helped a lot in increasing my knowledge.
Selenium testing training
Selenium Courses in Chennai
Selenium training Chennai
Software Testing Training in Chennai
Software Testing Courses in Chennai
Software Training Institutes in Chennai
This blog is more effective and it is very much useful for me.
ReplyDeletewe need more information please keep update more.
vmware training in bangalore
vmware courses in bangalore
vmware Training in Ambattur
vmware Training in Guindy
Nice post..
ReplyDeletesalesforce online training in hyderabad
salesforce online training hyderabad