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
michelle emanuel 59michelle emanuel 59 

Challenge Not yet complete... here's what's wrong: The Lead and Contact records with the last name 'Smith' were not found. Please add these records for this challenge.

Not clear what it is looking for I have a section in the code that pulls the Smith Records and I have added the Smith records.
<public class ContactAndLeadSearch {
    public static List<List<sObject>> searchContactsAndLeads(String searchName){
        
        List<List<Sobject>> contactsandleadsrecords =[find 'Smith' in all fields
                                      RETURNING contact(firstname,lastname),Lead(firstname,lastname)];
        
        List<List<sObject>> searchList = [FIND :searchName IN ALL FIELDS
                                      RETURNING Contact(FirstName,LastName),Lead(FirstName,LastName)];
        
        Contact[] smithContact1 = (Contact[])contactsandleadsrecords[0];
        Lead[] smithLead1 = (Lead[])contactsandleadsrecords[1];
        
        Contact[] searchContact = (Contact[])searchList[0];
        Lead[] searchLead = (Lead[])searchList[1];

        return searchList;
    }
}>
Amit Chaudhary 8Amit Chaudhary 8
Please check below post for solution. I hope that will help you
https://developer.salesforce.com/forums/?id=906F0000000BTk4IAG
Please try below class
Public Class ContactAndLeadSearch
{
        Public static List<List<sObject>> searchContactsAndLeads(String searchword)
        {
            String searchQuery = 'FIND \'' + searchword + '\' IN ALL FIELDS RETURNING Lead(Name,FirstName,LastName ), Contact(FirstName,LastName )';
            List<List<sObject>> searchConLead = search.query(searchQuery);
            return searchConLead;
        }
}

NOTE:- if you want to search same keyword in mutliple field then dnt add where you can try IN ALL FIELDS.

Execute below code in In Debug Annonymous window
 
List<List<sObject>> searchContactLead = ContactAndLeadSearch.searchContactsAndLeads('amit');

List<Lead> leadList = New List<Lead>();
List<Contact> contList = New List<Contact>();

leadList = ((List<Lead>)searchContactLead[0]);
contList = ((List<Contact>)searchContactLead[1]);

for(Lead a:leadList)
{
System.debug('Found following Leads ' + a.Name);
}
for(Contact cts:contList){
System.debug('Found following Contacts ' + cts.FirstName + '' + cts.LastName);
}
Please let us know if this will help you

NOTE:- Please create on contact and lead record with Smith name
Thanks
Amit Chaudhary


 
HARI KRISHNAHARI KRISHNA
Hi michelle emanuel,

  //perform the SOSL query
        List<List<SObject>> searchList = [
            FIND : 'smith' 
            IN NAME FIELDS 
            RETURNING 
            Lead(
                Id,
                Name
            )
        ];

here is the sample code snippet try to use it.Here 'companyName'  variable.
michelle emanuel 59michelle emanuel 59
The code was fine but to pass the validation I needed to do add the following code to the class:
<// Bulk insert all contacts with one DML call
        insert conList;

        // Create a list of le/ Create a list of contacts
        List<Contact> conList = new List<Contact> {
            new Contact(FirstName='Joe',LastName='Smith',Department='Finance'),
            new Contact(FirstName='Kathy',LastName='Smith',Department='Technology'),
            new Contact(FirstName='Caroline',LastName='Roth',Department='Finance'),
            new Contact(FirstName='Kim',LastName='Shain',Department='Education')};
            ads
        List<Lead> leadList = new List<Lead> {
            new Lead(FirstName='John',LastName='Smith', Company='IBM'),
            new Lead(FirstName='Mark',LastName='Smith', Company='ALU')
            };

>