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
Adam StaronAdam Staron 

how to pass variable in SOSL find query

Hi guys I want to use the SOSL to pass a variable inside the FIND query but I have no idea how to do that and if its even possible doing it that way. Here for example -
 
conn.query("Select {user variable here} IN ALL FIELDS RETURNING Account(Name), Lead(Id, Name)",
        function (err, res) {
            if (err) { return console.error(err); }
            console.log(res);
        }
    );

Any tips on how I can get around that?

Thank you very much for your time :) 
CharuDuttCharuDutt
Hii Adam
Try Below Code
public with sharing class DynamicSOSL{
    @AuraEnabled
    public static void SOSLQuery(String accountName){
        List<SObject[]> searchList = [FIND :accountName IN ALL FIELDS RETURNING Account(Name), Lead(Id, Name)];
         system.debug(searchList);
    }
}

Execute in Anonymous Window
DynamicSOSL.SOSLQuery('Edge');


Please Mark It As best Answer If It Helps
Thank You!