You need to sign in to do that
Don't have an account?

Covering Test Class
I am writing testclass for the belowing code.In that code 'List<List<SObject>> searchList = [Find : account.Name RETURNING Lead (Id, Name, Company, Owner.Name, Title, Phone, email, Status WHERE Status = 'Open' AND Company like :Names) ]; isn''t covering.How to cover this line?Anyone help to cover this?
public class TestController {
public Account Testaccount {get;set;}
public TestController() {
String accountId = ApexPages.CurrentPage().getParameters().get('Id');
if (accountId != NULL) {
account = [ SELECT Id, Name FROM Account WHERE Id =: accountId ];
String Names = account.Name+'%';
List<List<SObject>> searchList = [Find : account.Name RETURNING Lead (Id, Name, Company, Owner.Name, Title, Phone, email, Status WHERE Status = 'Open' AND Company like :Names) ];
List<Lead> leadLists = searchList[0];
}
}
}
@isTest(SeeAllData=true)
public class TController{
static testMethod void TController () {
Account acc = new Account(Name = 'Test11');
insert acc;
Lead testLead1 = new Lead (Status = 'Open',LastName = 'Test1',Email = 'gggg@gmail.com',Company = 'Test11-1',Phone = '1234545');
insert testLead1 ;
Lead testLead2 = new Lead(LastName = 'Test111-2', Company = 'Test11-2', Status = 'Open',Phone = '123345456');
insert testLead2;
System.assertEquals(testLead2.LastName , 'Test111-2');
ApexPages.CurrentPage().getParameters().put('Id',acc.Id);
TestController tlc = new TestController();
}
}
Also, in order to return results from your search query, you will need to set the ID of the result you want:
Test.setFixedSearchResults(new Id[]{ ID_HERE });
This is the only way to get results from a search.
All Answers
Your code is working fine, You need to check whether you have lead records or not
No.Still isn't covering.I have inserted two leads in Test class.It returns 0 rows in Debug.
05:23:55.825 (825033000)|SOSL_EXECUTE_BEGIN|[16]|FIND :tmpVar1 RETURNING lead(Id,Name,Company,Owner.Name,Title,Phone,email,Status WHERE (Status = 'Open' and Company like :tmpVar2))
05:23:55.826 (826699000)|SOSL_EXECUTE_END|[16]|Rows:0
How It is possible? I am writing a test class.Can you correct my test class or how to write test class for the belowing query?
List<List<SObject>> searchList = [Find : account.Name RETURNING Lead (Id, Name, Company, Owner.Name, Title, Phone, email, Status WHERE Status = 'Open' AND Company like :Names) ];
Also, in order to return results from your search query, you will need to set the ID of the result you want:
Test.setFixedSearchResults(new Id[]{ ID_HERE });
This is the only way to get results from a search.