function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ally Abdool Latiff MohabuthAlly Abdool Latiff Mohabuth 

SOQL query to retrieve record in last 24 hours

Hell0. I need a SOQL query to retrieve the  record created in last 24 hours.. I  need to the query and I am not using it in apex code. So I'm not able to use System.Now .. and If I use LAST_N_DAYS:1, it is not giming me specific last  24 hour range at any time in the day.
GuruGuru
Hello,

Last_n_days:1 should work fine. This is how the query would look:
select id from Account where createddate >= LAST_N_DAYS:1

Thanks
Ally Abdool Latiff MohabuthAlly Abdool Latiff Mohabuth
Last_n_days:1 is not giving me specific last 24 hours. It gives me from 12 AM to 11:59 PM of yesterday.
GuruGuru
In that case, the only solution I see is to enter the exact time stamp like below:

Consider the time as 4pm, 23rd sept 2016

select id from Account where createddate >= 2016-09-22T16:00:00Z
Ally Abdool Latiff MohabuthAlly Abdool Latiff Mohabuth
problem is the query is used everyday in a conga query
Robert Kubovic 2Robert Kubovic 2
You can create a formula field on the record that evaluates the time compared to the moment you run the Conga solution.   Formula would look something like so:  SUBSTITUTE(TEXT((TODAY() - 1)), "/", "-") & "T" & TEXT(TIMEVALUE(NOW())) & "Z"     Then you can use the value of this formula and pass it into pv0 for your Conga Query (created date >= {pv0} ) to pull in the latest 24 hours information.