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
Ashok S 7Ashok S 7 

how can i slove the sosl problem

Hai guys.
i Have the following requirment.
The Apex class must be called 'ContactAndLeadSearch' and be in the public scope.
The Apex class must have a public static method called 'searchContactsAndLeads'.
Because SOSL indexes data for searching, you must create a Contact record and Lead record before checking this challenge. Both records must have the last name 'Smith'. The challenge uses these records for the SOSL search.
The return type for 'searchContactsAndLeads' must be 'List<List< SObject>>'
The 'searchContactsAndLeads' method must accept an incoming string as a parameter, find any contact or lead that matches the string as part of either the first or last name and then return those records.

as per above requirment i created the class
public class ContactAndLeadSearch
{
    public static List<List< SObject>> searchContactsAndLeads(string s1,string s2)
    {
      list<contact> conlist = new list<contact>();
      list<lead> leadlist = new list<lead>();
       List<List< SObject>> ss = [Find 's1' IN ALL FIELDS Returning contact(lastname),lead(name,company)];
       conlist =((list<Contact>)ss[0]);
       leadlist = ((list<lead>)ss[1]);
       return null;
     }
}

and i getting the following error
Executing the 'searchContactsAndLeads' method failed. Either the method does not exist, is not static, or does not return the expected search results.
please help me any one
 
KaranrajKaranraj
Ashok - There are couple of things you have to make change in your code
  • As per the challenge you have to return List<List<sobject>>, but in your method you are returning NULL, You don't need conlist and leadlist variables in your code
  • As per the Last point of the challenge requirement "the search string matches either first name or last name of lead and contact, so you have to include the where condition for the lead and contact with first name or last name 
Ashok S 7Ashok S 7
please can u send me the code 
KaranrajKaranraj
Ashok - I can share you the code, but that's not the purpose of Trailhead Its for the self-learning, try with my suggestions you can able to complete it without any issues. Here is the reference link for the where condition - https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_where.htm 

Let us know, if you need any help.
Ashok S 7Ashok S 7
 Thanks for ur suggestions
Ashok S 7Ashok S 7
please explain antoher requirment details please
The Apex class must be called 'AccountHandler' and be in the public scope.
The Apex class must have a public static method called 'insertNewAccount'.
The 'insertNewAccount' method must accept an incoming string as a parameter, name the account after the parameter, insert it into the system and then return the account record.
The 'insertNewAccount' method must also accept an empty string, catch the failed DML and return null.
KaranrajKaranraj
@Ashok - Can you please open a new thread? 
Ashok S 7Ashok S 7