You need to sign in to do that
Don't have an account?
hermi
Date field on a query string
HI,
I am trying to develop a batch class where i need to query the value of a date field, but i am getting the following error. Please help.
date newdate=system.today()+6;
//String targetDate = targetDateval.format('yyyy-MM-dd')+'T'+targetDateval.format('HH:mm:ss')+'Z';
system.debug(' Date'+newdate);
query= 'Select recordtypeid,ispersonaccount,id,ownerid,Date_to_Call__c from Account';
query+= ' Where Date_to_Call__c ='+'\''+newdate+'\'' +' or Date_to_Call__c = today ';
Error: value of filter criterion for field 'Date_to_Call__c' must be of type date and should not be enclosed in quotes
if i dont enclose it in quotes and if i just give the query as following, i am getting other error
query= 'Select recordtypeid,ispersonaccount,id,ownerid,Date_to_Call__c from Account';
query+= ' Where Date_to_Call__c ='+newdate+' or Date_to_Call__c = today ';
error: line 1:277 no viable alternative at character ' '
Please suggest any ideas..
Simply...http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_select_dateformats.htm
Thanks for the reply Mike...I tried changing the format but its still giving the same error. Can you post some sample code if you have any. I think usage of escape characters for Date field is different.
Thanks in Advance
Did you try the following?
query+= ' Where Date_to_Call__c = :newDate or Date_to_Call__c = today ';
Try this for formating the date: