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
Craig PhoenixCraig Phoenix 

Email Alert From Case Volume Hourly

Hello,

I have spent time reviewing multiple questions and trying to built on my own but due to just starting out with development in Salesforce my knowledge is limit.

I found these two questions that closely mirror what my team needs (Send Email when cases hit certain criteria (https://developer.salesforce.com/forums?id=906F0000000kGjEIAU) and Email alert if number of opened cases reaches certain value (https://developer.salesforce.com/forums/?id=906F0000000AXeBIAW))

What I am needing to create is a system where either of the two items trigger an automated email to senior leadership
1 - Checks the current open cases within the last 60 minutes from when the program runs, so program runs every 30 minutes and looks back at the last 60 minutes to see if 10 or more cases were opened within the last 60 minutes.
2 - Every hour the program runs and looks back at the last hour and IF 10 or more cases opened it sends an email alert.

Any help is greatly appreciated.
Best Answer chosen by Craig Phoenix
Craig PhoenixCraig Phoenix
I figured it out by using 
 
List<Case> numberofcases = [SELECT ID FROM CASE where Age__c<=1];

Basically created a new field called Age and within that field I did the formula (NOW() - CreatedDate )*24, using this I was able to filter to just list cases that were under "1" which is the count for 1 hour with that formula.

All Answers

Craig PhoenixCraig Phoenix
I been working on this for a while and I am so close but cannot get this one issue resolved.

I have the cases pulling and flagging the case that hits the limit but when I try to designate to only list cases with CreatedDate of Today && Flag Age under <=1 I get the error "Variable doesnotexist: FLAGS__Case_Flag_Age__c"

How do I enable the Trigger to see the custom field?

Code below:
trigger OutageAlert on Case (before insert) {
    date today =system.today();
    List<Case> numberofcases = [SELECT ID FROM CASE where CreatedDate>=:today && FLAGS__Case_Flag_Age__c<=1.00];
        for(case cas:trigger.new){
            if(cas.origin == 'Email'){
                if(numberofcases.size() == 5) {
                    cas.SendAlert__c = true;
                }
                if(numberofcases.size() == 10) {
                    cas.SendAlert__c = true;
                }
            }
        }
}

I have a workflow on the end that once the "SendAlert__c" is flagged it fires off the email to alert my admin team.
Craig PhoenixCraig Phoenix
I figured it out by using 
 
List<Case> numberofcases = [SELECT ID FROM CASE where Age__c<=1];

Basically created a new field called Age and within that field I did the formula (NOW() - CreatedDate )*24, using this I was able to filter to just list cases that were under "1" which is the count for 1 hour with that formula.
This was selected as the best answer