+ Start a Discussion

No viable alternative at character ' ' on dynamic SOQL query date

I'm trying to implement a query built from other variables, I'm getting it from the part highlighted in red. I figured this by trial-and-error. Why is this not working? I can get the query to run with all other conditions when that field (dateFilter.Date__c) is excluded. It works in a standard SOQL query, but I need a dynamic one because of the namestring.


There is definitely a date variable being assigned at this point in the query.


if(this.selectedCode.Name != null){
            this.clientCCs = Database.query('SELECT ClientCode__c,Sent_Date_Time__c,Lead_Status__c, No_Count_Reason__c, Body__c,Subject__c,From__c,Page_Source__c,HTTP_Referer__c,Client_Selection_Method__c,P1C_CCID__c,ClientCode__r.Account_Manager__c,AM__c,Syndication__c FROM Client_CC__c WHERE Lead_Status__c = ' + this.leadStatus + ' AND Sent_Date__c > ' + this.dateFilter.Date__c + ' AND ClientCode__r.Name LIKE ' + '\'%' + this.nameString + '%\'' + ' LIMIT ' + this.queryLimit);




For a dynamic query, you have assemble a string that looks exactly right, as if you were using a bind variable. In this case, you want your date string to be formatted correctly: yyyy-mm-dd


Hope this helps,