0

I am doing the Write SOSL Queries Trailhead module. I am getting an error.

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.

And my code

public class ContactAndLeadSearch {

public static List<List<SObject>> searchContactsAndLeads(String param)
{
    Contact a = new Contact();
    a.LastName='Smith';
    insert a;

    Lead b = new Lead();
    b.LastName='Smith';
    insert b;

    List<List<SObject>> retval = [FIND 'Smith' IN ALL FIELDS RETURNING Contact(Name, LastName, FirstName where LastName=:param or FirstName=:param), Lead(Name, LastName, FirstName where LastName=:param or FirstName=:param)];
    return retval;
}
}

Pretty sure its my query that is wrong.

2
  • For what is worth, the trailhead challenges sometimes give errors unrelated to the real problem. The discussion linked from the trailhead page usually clears this up. – user12646 Jan 27 '18 at 22:23
  • "Please add these records" makes it sound like you need to actually generate data. Have you done so? – Adrian Larson Jan 27 '18 at 22:41
3

Read these directions:

Prerequisites
Some queries in this unit expect the org to have accounts and contacts. If you haven’t created the sample data in the SOQL unit, create sample data in this unit. Otherwise, you can skip creating the sample data in this section.

If you continue reading, you will see a script which will generate some sample data for you.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.