You need to sign in to do that
Don't have an account?
DJP1S
Annoying DateTime problem with dynamic SOQL...
I keep getting a "no viable alternative at character ' '" error whenever I try to compare a datetime value of an sObject to CreatedDate.
Basically, I keep getting this written out in my query:
AND CreatedDate > 2010-01-08 00:00:00
Rather than this:
AND CreatedDate > 2010-01-08T00:00:00Z
This is driving me crazy. Any ideas on how to fix?
Here's my visualforce component
<b>Notes Back To: </b> <apex:inputField value="{!dateFilter.Start_Time__c}"required="false"/>
Which plugs into this part of my controller
this.query = 'SELECT Name, ClientCode__c, ClientCode__r.Name, DOW_Created__c, Project__c, ID, Account__c, Prompt__c,Note__c, Seq__c, CreatedBy.Name, CreatedDate, Important__c, Note_Type__c, Department__c, Note_Group__r.Name, Page1Task__c, Status__c, Date__c FROM Note__c WHERE CreatedBy.Name != null'; system.debug('%%% query: ' + this.query); if(this.dateFilter.Start_Time__c != null){ this.query = this.query + ' AND CreatedDate > ' + dateFilter.Start_Time__c; system.debug('%%% query: ' + this.query); }
You can try this:
DateTime startDate = dateFilter.Start_Time__c;
Replace the following line
this.query = this.query + ' AND CreatedDate > ' + dateFilter.Start_Time__c;
with
this.query = this.query + ' AND CreatedDate > :startDate '; // be sure to declare startDate at the beginning of the function.
All Answers
You can try this:
DateTime startDate = dateFilter.Start_Time__c;
Replace the following line
this.query = this.query + ' AND CreatedDate > ' + dateFilter.Start_Time__c;
with
this.query = this.query + ' AND CreatedDate > :startDate '; // be sure to declare startDate at the beginning of the function.
Excellent, thank you!