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
Howard WeinsteinHoward Weinstein 

Error in SOSL Challenge

I keep getting this error which does not seem right in the SOSL challenge
Challenge not yet complete... here's what's wrong:
There was an unexpected error in your org which is preventing this assessment check from completing: System.TypeException: Invalid conversion from runtime type List

Here is my code
public class ContactAndLeadSearch {

     public static List<List<SObject>> searchContactsAndLeads (String InputName){
        
       list<list<sObject>> searchlist = [FIND :InputName IN NAME FIELDS
                   RETURNING Contact(ID,FirstName,LastName), Lead(ID,FirstName, LastName)];
        

   
        Lead[] searchLeads = (Lead[])searchlist[0];
        Contact[] searchContacts = (Contact[])searchlist[1];
      
}
}
Best Answer chosen by Howard Weinstein
pconpcon
You aren't returning the search list at all.  I think you just want to do
 
public class ContactAndLeadSearch {
    public static List<List<SObject>> searchContactsAndLeads (String InputName) {
        return [
            FIND :InputName
            IN NAME FIELDS
            RETURNING Contact(ID,FirstName,LastName),
                Lead(ID,FirstName, LastName)
        ];
    }
}

NOTE: Please use the "Add a code sample" button (icon <>) when including code

All Answers

pconpcon
You aren't returning the search list at all.  I think you just want to do
 
public class ContactAndLeadSearch {
    public static List<List<SObject>> searchContactsAndLeads (String InputName) {
        return [
            FIND :InputName
            IN NAME FIELDS
            RETURNING Contact(ID,FirstName,LastName),
                Lead(ID,FirstName, LastName)
        ];
    }
}

NOTE: Please use the "Add a code sample" button (icon <>) when including code
This was selected as the best answer
James LoghryJames Loghry
Hi Howard,

This doesn't look like valid code, as it would error when you try to compile because you're missing a return statement.  Try refreshing or grabbing the latest class in developer console to make sure you have the write code that is erroring out.  That being said, for this partiular challenge you should only need to return the searchList variable if I remember correctly and not the searchLeads / searchContacts piece.