+ Start a Discussion
Beatriz MinguezBeatriz Minguez 

Function Parameter in SOSL code

The sSearchWord is giving me a compiling error. Can anyone tell me how to use sSearchWord in the SOSL code as a parameter?
public class ContactAndLeadSearch {

    public static List<List< SObject>> searchContactsAndLeads (string sSearchWord) {

         List<List<sObject>> searchList = [FIND sSearchWord IN ALL FIELDS 
                   RETURNING Contact(FirstName,LastName), Lead(FirstName,LastName)];

Thanks, 

Bea
Best Answer chosen by Beatriz Minguez
pconpcon
You'll want to use the : to include it as a variable.  Take a look over this documentation [1].
 
List<List<sObject>> searchList = [
    find :sSearchWord in all field
    returing Contact(FirstName, LastName),
        Lead(FirstName,LastName)
];

[1] https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL_variables.htm