function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Madevala JithenderMadevala Jithender 

How do i write test class for my code

public class ContactandLeadSearch {
    public static list<list<sobject>> searchcontactsandleads(string lastname){
        
        list<list<sobject>> contactleadlist = [find : lastname in all fields returning contact (name),Lead(name)];
        return contactLeadlist;
    }

}
Best Answer chosen by Madevala Jithender
CharuDuttCharuDutt
Hii Madevala
Try Below Test Class 100%
@istest
public class ClosedOpportunityTriiggerTest {

static testMethod void testAccount(){

Lead L = new Lead();
L.FirstName = 'Test';
L.LastName = 'Lead';
L.company = 'test company';

insert L;

contact con = new contact();
con.FirstName = 'Test';
con.LastName = 'Lead';

insert con;

ContactandLeadSearch.searchcontactsandleads('Test Lead');

}

}
Please Mark It As Best Answer If It Helps
Thank You!

All Answers

AnkaiahAnkaiah (Salesforce Developers) 
 
@istest
public class ContactandLeadSearchTest {

static testMethod void ContactandLeadmethod(){

Lead L = new Lead();
L.FirstName = 'Test';
L.LastName = 'Lead';
L.company = 'test company';

insert L;

contact con = new contact();
con.FirstName = 'Test';
con.LastName = 'Lead';

insert con;

ContactandLeadSearch.searchcontactsandleads('Test Lead');

}

}

If this helps, Please mark it as best answer.

Thanks!!
CharuDuttCharuDutt
Hii Madevala
Try Below Test Class 100%
@istest
public class ClosedOpportunityTriiggerTest {

static testMethod void testAccount(){

Lead L = new Lead();
L.FirstName = 'Test';
L.LastName = 'Lead';
L.company = 'test company';

insert L;

contact con = new contact();
con.FirstName = 'Test';
con.LastName = 'Lead';

insert con;

ContactandLeadSearch.searchcontactsandleads('Test Lead');

}

}
Please Mark It As Best Answer If It Helps
Thank You!
This was selected as the best answer