6

How to define the "where clause" in SFDC SOQL to extract the date that have been modified in last 24 hours. Thanks.

PS : I am using the QUERY rest URI for query the data.

1 Answer 1

19

You can use the existing LastModifiedDate or SystemModStamp fields in your SOQL query (See System Fields). The LAST_N_DAYS or TODAY date literals may be useful. Otherwise you can use a specific calculated UTC Date time value.

Select Id from Account where SystemModStamp >= LAST_N_DAYS:1
Select Id from Account where SystemModStamp >= 2014-11-19T23:01:01Z

There was a recent blog post on the performance implications of LastModifiedDate vs SystemModStamp - Force.com SOQL Performance Tips: LastModifiedDate vs SystemModStamp

4
  • Thanks it's working fine.. what's the difference between systemModStamp and lastmodifiedDate. Commented Nov 20, 2014 at 20:48
  • @AnkitKhandelwal The differences are covered in the linked System Fields and Performance Tips pages. SystemModstamp gets updated for all changes and is strictly read-only. LastModifiedDate is only for user changes and can be updated. Commented Nov 20, 2014 at 21:28
  • Below query won't give last 24 hours data , if I don't run it @ 12 in Midnight.. I have a java program that schedule @ 8 pm ever ngiht and I have get the data for last 24 hours. /services/data/v32.0/query/?q=select ID from Custom_Object_HDS__c where LastModifiedDate = Today Commented Nov 21, 2014 at 1:05
  • @AnkitKhandelwal look at the definitions of the Date Time literals. They are defined along the lines of "Starts 12:00:00 of the current day and continues for 24 hours". You will need to manually calculate the required UTC date literal as per the second example query. Commented Nov 21, 2014 at 1:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .