[SalesForce] I wanna run the SOSL to search for a string obtained by function parameter

I wanna search for a particular string obtained by my function parameter in Contact & Lead FirstName & LastName fields..
The difficulty is how to compose a SOQL statement for that,as I am getting problem with the following piece of code:
enter image description here

However when I pass a string,it works perfect,it is not just allowing the parameter obtained to be passed in the query..

Code that works

Am I doing something wrong?
Please let me know…

Best Answer

I'm pretty sure there's a duplicate out there somewhere, but the answer is you have to bind to the query:

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

Do not use the quote (') or the ({}) characters. You can bind directly to a variable.

Related Topic