0

We have issue with one of the apex class which stopping us from configuring a record through lightning component. When we debugged the issue we found this error in debug logs and could not identify what is the issue related to.

Class:

public with sharing class customLookUpController {

 @AuraEnabled
public static List <sObject> fetchLookUpValues(String searchKeyWord, String objectName, String queryFilterField, String fieldsToQuery) {  
    String searchKey = searchKeyWord + '%';
    fieldsToQuery = fieldsToQuery != '' ? ', '+fieldsToQuery : fieldsToQuery;
    String sQuery = 'SELECT id, Name'+fieldsToQuery+' FROM '+objectName+' WHERE Name LIKE \''+searchKey+'\' '+queryFilterField+' ORDER BY createdDate DESC LIMIT 5';
    
    List<sObject> returnList = new List<sObject>();
    for (sObject obj : Database.query(sQuery)) returnList.add(obj);
    return returnList;
}


@AuraEnabled
public static List <sObject> fetchLookUpValues(String searchKeyWord, String objectName, String queryFilterField) {  
    String searchKey = searchKeyWord + '%';
    String sQuery = 'SELECT id, Name FROM '+objectName+' WHERE Name LIKE \''+searchKey+'\' '+queryFilterField+' ORDER BY createdDate DESC LIMIT 5';
    
    List<sObject> returnList = new List<sObject>();
    for (sObject obj : Database.query(sQuery)) returnList.add(obj);
    return returnList;
}

@AuraEnabled
public static List <sObject> fetchLookUpValuesNew(String searchKeyWord, String objectName, String queryFilterField, String fields, String queryConditions) {  
    String searchKey = searchKeyWord + '%';
    String sQuery;
    //String allfields = '';
    if(queryConditions != null && queryConditions != ''){
        sQuery = 'SELECT '+fields+' FROM '+objectName+' WHERE '+queryFilterField+' LIKE \''+searchKey+'\' '+' AND '+ queryConditions +' ORDER BY createdDate DESC LIMIT 10';
        System.debug('sQuery--'+sQuery);
    }
    else{
        sQuery = 'SELECT '+fields+' FROM '+objectName+' WHERE '+queryFilterField+' LIKE \''+searchKey+'\' '+' ORDER BY createdDate DESC LIMIT 10';
        System.debug('sQuery--'+sQuery);
    }     
    List<sObject> returnList = new List<sObject>();
    for (sObject obj : Database.query(sQuery)) returnList.add(obj);
    return returnList;
}    

}

Error:

Class.customLookUpController.fetchLookUpValues: line 10, column 1 08:11:59.0 (2330323)|FATAL_ERROR|System.QueryException: expecting a colon, found ')'

Debug log:

51.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,NONE;DB,INFO;NBA,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WAVE,INFO;WORKFLOW,INFO
08:11:59.0 (163644)|USER_INFO|[EXTERNAL]|0052p000009sYJY|ramkumar.murugesan@lntinfotech.com-cte.uat|(GMT+01:00) Central European Standard Time (Europe/Paris)|GMT+01:00
08:11:59.0 (211455)|EXECUTION_STARTED
08:11:59.0 (217359)|CODE_UNIT_STARTED|[EXTERNAL]|apex://customLookUpController/ACTION$fetchLookUpValues
08:11:59.0 (1287969)|CODE_UNIT_STARTED|[EXTERNAL]|01p57000001MmYo|customLookUpController.fetchLookUpValues(String, String, String, String)
08:11:59.0 (2176405)|EXCEPTION_THROWN|[10]|System.QueryException: expecting a colon, found ')'
08:11:59.0 (2316403)|FATAL_ERROR|System.QueryException: expecting a colon, found ')'

Class.customLookUpController.fetchLookUpValues: line 10, column 1
08:11:59.0 (2330323)|FATAL_ERROR|System.QueryException: expecting a colon, found ')'

Class.customLookUpController.fetchLookUpValues: line 10, column 1
08:11:59.2 (2340395)|CUMULATIVE_LIMIT_USAGE
08:11:59.2 (2340395)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of Publish Immediate DML: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

08:11:59.2 (2340395)|CUMULATIVE_LIMIT_USAGE_END

08:11:59.0 (2370892)|CODE_UNIT_FINISHED|customLookUpController.fetchLookUpValues(String, String, String, String)
08:11:59.0 (2533470)|CODE_UNIT_FINISHED|apex://customLookUpController/ACTION$fetchLookUpValues
08:11:59.0 (2542518)|EXECUTION_FINISHED
6
  • Please debug searchKeyWord, objectName, queryFilterField and fieldsToQuery in the first fetchLookUpValues method where the error is happening. Mar 10, 2021 at 14:14
  • Log the actual query string being executed. The problem will almost certainly become visible immediately.
    – David Reed
    Mar 10, 2021 at 14:59
  • @DavidReed I tried System.debug (sQuery); but the log did not provided me the query results. Mar 10, 2021 at 15:08
  • Not the results, what is the actual query that you are trying to execute that results in the exception being thrown.
    – David Reed
    Mar 10, 2021 at 15:34
  • @DavidReed Here is the query i received "SELECT id, Name, Multi_Temperature__c, Undermount__c, CC_Parent__c FROM SG_ProductBook__c WHERE Name LIKE '%' AND CC_Enabled__c=true AND (id IN ) OR CC_Parent__c IN )) ORDER BY createdDate DESC LIMIT 5" Mar 10, 2021 at 15:47

1 Answer 1

2

As stated in a comment, the actual query being executed is

SELECT id, Name, Multi_Temperature__c, Undermount__c, CC_Parent__c 
FROM SG_ProductBook__c 
WHERE Name LIKE '%' AND CC_Enabled__c=true AND (id IN ) OR CC_Parent__c IN )) 
ORDER BY createdDate DESC LIMIT 5

That immediately shows the problem:

(id IN ) OR CC_Parent__c IN )

One of the strings you are templating in to build a WHERE clause is not valid SOQL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.