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
TSMETSME 

SOSL bind variable in apex not working anymore

We have a lightning component that does a looup on the asset object based on input in a text field. 
Until yesterday we had following code in our apex controller to perform the query: 

String searchString = '\'*'+userInput+'*\'';
String soslQuery = 'FIND :searchString IN ALL FIELDS RETURNING '
                         + type +'(Id, name,SerialNumber ORDER BY name'+') LIMIT 20';
List<List<SObject>> results =  Search.query(soslQuery);

However today we noticed that this code isn't working anymore as the results list is always empty. 
Replacing the soslQuery code with the following fixes the issue: 

String soslQuery = 'FIND ' + searchString + ' IN ALL FIELDS RETURNING '
                         + type +'(Id, name,SerialNumber ORDER BY name'+') LIMIT 20';

What are wemissing? Isn't a bind variable not supported anymore in these kind of queries? Or is there anything wrong in the use of them? 

Regards,
​Thomas
Raj VakatiRaj Vakati
Try this ...... 
below is working for me 
 
String userInput='uni';
String type=' Account ' ;
String searchString = '\'*'+userInput+'*\'';
String soslQuery = 'FIND ' + searchString + ' IN ALL FIELDS RETURNING '
                         + type +'(Id, name ORDER BY name) LIMIT 20';

 
List<List<SObject>> results =  Search.query(soslQuery);
System.debug('results'+results);


Your code .. Space was issue 
 
String soslQuery = 'FIND ' + searchString + ' IN ALL FIELDS RETURNING '
                         + type +' (Id, name,SerialNumber  ORDER BY name) LIMIT 20';

 
List<List<SObject>> results =  Search.query(soslQuery);


 
TSMETSME
Hi Raj,

Thanks for your answer, but my main question is why following code isn't working anymore, while it was before: 
 
String searchString = '\'*'+userInput+'*\'';
String type = 'Asset'
String soslQuery = 'FIND :searchString IN ALL FIELDS RETURNING '
                         + type +'(Id, name,SerialNumber ORDER BY name'+') LIMIT 20';
List<List<SObject>> results =  Search.query(soslQuery);
So using a bind variable instead of your solution, as that one is working for me too. 
However until 2 days ago above code was running fine in production, but suddenly we don't get any results anymore. 
Replacing it with similar code as your example works fine..