How to query the data that has been modified in last 24 hours

  • 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.

  • 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

    Thanks it's working fine.. what's the difference between systemModStamp and lastmodifiedDate.

    @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.

    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

    @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.

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM

Tags used