• Phani Surapaneni
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi,
I'm stuck on this trailhead challenge.
Here's the link of the challenge page:

https://developer.salesforce.com/trailhead/force_com_programmatic_beginner/apex_database/apex_database_sosl#challenge
and this is the error message that appears in red:

Challenge not yet complete... here's what's wrong: 
Executing the 'searchContactsAndLeads' method failed. Either the method does not exist, is not static, or does not return the expected search results.


Here is my class:

//The apex class in public domain
public class ContactAndLeadSearch {
    
    //public static method that takes a String parameter
    
    public static SObject[] searchContactsAndLeads(String input) {
        
        //Create list of two lists, one for Contacts and the second for Leads
        List<List<SObject>> searchResults = [FIND :input
                                            IN NAME FIELDS
                                            RETURNING Contact(Name), Lead(Name)];
        
        //Place list of contacts at position 1 and leads at 2
        Contact[] searchContacts = (Contact[])searchResults[0];
        Lead[] searchLeads = (Lead[])searchResults[1];
        
        //return the two lists - I think this is where the problem is.
        return searchContacts;
        return searchLeads;
        
    }

}

After fiddling around a little I have managed to get to the stage where no problems appear in the Problems tab in developer console. But I suspect the code would only execute up to first return method on second last line 'return searchContacts;'

thanks