You need to sign in to do that
Don't have an account?
System.QueryException: unexpected token: 'LIMIT' when debugging a class
Hi there!
I'm new at Salesforce and I'm trying to debug a class but I'm receiving this error "System.QueryException: unexpected token: 'LIMIT' at line 24, column 1. Can anyone advise what is wrong_ as I cannot seem to find the answer, thanks
public with sharing class dvd_CustomLookupController {
@AuraEnabled(cacheable=true)
public static List<sObject> search(String searchTerm, String searchField, string myObject, String filter) {
String myQuery = null;
String searchFieldWhere;
system.debug(searchTerm+':'+searchField+':'+myObject+':'+filter);
if(String.isBlank(searchField)){
searchField = ' ';
searchFieldWhere = 'Name';
}else{
searchFieldWhere = searchField;
searchField = ' ,' + searchField;
}
if(String.isNotBlank(filter)){
myQuery = 'Select Id, Name '+searchField+' from '+myObject+' Where '+searchFieldWhere+' Like \'%' + searchTerm + '%\' AND '+filter+' LIMIT 5';
}else {
if(String.isBlank(searchTerm)){
myQuery = 'Select Id, Name '+searchField+' from '+myObject+' Where LastViewedDate != NULL ORDER BY LastViewedDate DESC LIMIT 5';
}else {
myQuery = 'Select Id, Name '+searchField+' from '+myObject+' Where '+searchFieldWhere+' Like \'%' + searchTerm + 'DESC LIMIT 5';
}
}
List<sObject> lookUpList = database.query(myQuery);
system.debug(myQuery);
system.debug(lookUpList.size());
return lookUpList;
}
}
Please use below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
All Answers
I need the way you are calling the class should be different. By just giving the filter field will give you the error.
You need to mention exact filter for that as below.
If you just give the Active__c field in the last parameter the query returned is as below which is cauing the issue.
Just put the debug statement after every myquery variable so you will get what the query is and where it is causing the issue.
If this solution helps, please mark it as best answer.
Thanks,
Please use below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
I knew there was something wrong in the query string, I just couldn't figure out what was it