Hi I am trying to make a dynamic SOSL on the basis of certain condition, but getting the error as script thrown exception.
below is my code :
List<List<ABC__c>> list1 = new List<List<ABC__c>>();
String searchQuery = makeDynamicQuery(textA,textB);
list1 = search.query(searchQuery);
public static String makeDynamicQuery(String textA, String textB) {
String makeQuery = null;
String sampleSearchab = textA +'*';
if(sampleSearchab.length()>1 && textB!=null ) {
if(textB == 'All') {
makeQuery = 'FIND\'sampleSearchab\'IN ALL FIELDS RETURNING ABC__c(Field1, '+
'Field2,Field3,Field13'+
'WHERE Field2 = true ORDER BY Field13)';
}
if(textB == 'True') {
makeQuery = 'FIND\'sampleSearchab\'IN ALL FIELDS RETURNING ABC__c(Field1, '+
'Field2,Field3,Field13'+
'WHERE Field2 = true AND Field3=true ORDER BY Field13)';
}
}
return makeQuery;
}
Error : Script thrown exception…
kindly help me out:
Best Answer
The query is malformed. Here is the correct way - added a space before
WHERE
andsampleSearchab
concatenated the right way.