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
Timothy SmithTimothy Smith 

SOQL number of cases created by same account in (n) hours

Is there a way to run a SOQL search for number of cases ran in 40 hours.  My org is looking to send a notification via email anytime an Account has created 8 or more cases within a 40 hour period. 

I am aware that I can use Last_N_Days, just wondering if there is a way to use hours.
 
Best Answer chosen by Timothy Smith
SFDC Coder 1SFDC Coder 1
Hi Timothy Smith,

Yes, there is no option currently we have in SOQL which can be used directly to to get the cases which are in last 40 hours. But we have an alternative where we can use Date time variable and use same variable in SOQL to get the cases whcih are created in last 40 hours.

Sample snippet of defining variable is as follows.

Datetime myDateTime = Datetime.newInstance(2001, 2, 1);
system.debug(myDateTime);
myDateTime = myDateTime.addHours(-40);
system.debug(myDateTime);

PS.  If it helps you then mark this answer as 'Best Answer'. Thanks.