You need to sign in to do that
Don't have an account?
rushi ettam 7
passing string parameter to sosl searchQuery
in Apex Basics&Database SOSL Queries
We have challenge to pass the string parameter as input and depend upon that string made sosl query
but in reality how can you make that
searchQuery in SOSL accept text search
syntax as find 'smith' in all fields
So the question is how can we put the variable name in place of string???
We have challenge to pass the string parameter as input and depend upon that string made sosl query
but in reality how can you make that
searchQuery in SOSL accept text search
syntax as find 'smith' in all fields
So the question is how can we put the variable name in place of string???
Hi Rushi,
You need to construct a query string with your search string like below and use search.query(searchQuery):
Where searchstring is the string you want to search.
Thanks
All Answers
Hi Rushi,
You need to construct a query string with your search string like below and use search.query(searchQuery):
Where searchstring is the string you want to search.
Thanks
I know this is a bit old, but you can also access a String variable within a SOSL query using a colon before the String variable.
For example,
public static List <List <SObject> > searchContactsAndLeads(String str) {
List <List<SObject>> searchList = [FIND :str IN ALL FIELDS RETURNING Contact(FirstName,LastName),Lead(FirstName,LastName)];
return searchList;
}
Public static List<List<SObject>> searchContactsAndLeads(String Param){
List<List<SObject>> searchList=[FIND :Param IN ALL FIELDS RETURNING Contact(FirstName, LastName), Lead(LastName, Company)];
return searchList;
}
}
public static List<List<sObject>> searchContactsAndLeads(String a)
{
List<List<sObject>> searchList = [FIND :a IN ALL FIELDS RETURNING Contact(FirstName,LastName) , Lead(FirstName,LastName)];
return searchList;
}
}