You need to sign in to do that
Don't have an account?
Goodluck123
Passing datetime to query in apex class dynamically.
Select Id from objectname__c where source__c = SF and lastmodifieddate < 2010-02-03T00:15:00.000Z
This query is working fine in eclipse, but I want the same query passing datetime to query in apex class dynamically.
Please let me know how to frame my query in apex class.
Thanks in Advance..
PK
Thanks for your reply,
What is the format for dateFrom and dateTo in the parameters you mentioned.can you please explain me how you are doing.
Hi,
I think that depends on your needs and use case, if you need a DateTime or a Date only, the requirements for those dates ranges, so far I'm using these methods and formats for conversion using Apex,
DateTime
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_datetime.htm
Date
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_date.htm
Here you might find some suitable information of how to parse Dates,
Regards.
Thanks,
Let me research on this, will update you after fixing my issue.
I found the answer on this web site: Link to Answer
Code can look like this...
datetime dtStart;
datetime dtEnd;
dtStart = dateTime.now().addDays(-1);
dtEnd = dateTime.now()
extraWhereForQuery = ' AND CreatedDate >= ' + dtStart.format('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'') +
' AND CreatedDate <= ' + dtEnd.format('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'');