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
priyanka mohapatrapriyanka mohapatra 

Send alert when last case created is more than 5 days

I've a requirement where I need to send an alert when the last case created for each category (record type) is more than 5 days from today. Example: For record type "A", the last record created was on June 5, 2023. So, I should be sending an alert for this record type. I've created a Schedule Trigger Flow which runs at a particular interval and is sending an alert when it finds the last record for all the record types created was more than 5 days. How do I put a loop inside this to segregate the records according to the record type and send alerts for each record type. This is how my Flow and the "Get Cases" node are looking now: 
User-added imageUser-added imageHow do I segregate the records based on record types? Please advise. Thanks.
Arun Kumar 1141Arun Kumar 1141
Hi Priyanka,

You may alter your current Flow as follows to separate the records depending on record Types and issue alerts for each record type separately:

1.To iterate through each record fetched by the "Get Cases" node, add a Loop element after the "Get Cases" node.
2.Add a Decision element to the Loop to determine the current case's record type. The current case's record type can be obtained and saved in a variable by using the "Get Record Type" element.
3.After that, include a Filter element to sort the cases according to record type. To filter the cases, use the variable that contains the record type.
4.Put a Formula element after the Filter element to figure out how many days have passed since the last case in the filtered list was created. The most recent case created for each record type can be obtained by using the "Get Records" element with a sorting option.
5.Add a decision element to determine whether the number of days exceeds 5.
6.Add an Action element to issue an alert for that record type if the number of days exceeds 5.
7.Add an End element to end the flow lastly, outside the Loop.

Here's an example representation of the modified Flow:
- Start
- Get Cases
- Loop
  - Get Record Type (store in a variable)
  - Decision (check record type)
    - Filter Cases (based on record type)
    - Get Records (sorting: creation date, descending, limit: 1)
    - Formula (calculate days between current date and last case creation date)
    - Decision (check if days > 5)
      - Action (send alert for record type)
  - Loop Exit (if no more cases)
- End

This logic will cause the Flow to iterate over each case, separate them based on the types of records they include, and send alerts for each record type separately if the creation date of the most recent case is more than five days ago.

Thanks
SwethaSwetha (Salesforce Developers) 
HI @Priyanka,
I see you also posted on https://salesforce.stackexchange.com/questions/405111/send-alert-when-last-case-created-is-more-than-5-days for which a formula update has been suggested

Please mark the answer best to close this thread so it can help others facing same issue in future.Thank you
Andrew Gillan 30Andrew Gillan 30
Go back to scratch and rethink the problem.

I would create a custom reference object,
Create one record per record type.
Build a flow that when the case is created, populate a date field in the reference document for the matching record type.
Then build a scheduled flow on the reference object where you can simply send an alert based on the date stamp.

This would reduce processing / run time as it would be running over a collection of records that is no bigger than the number of record types for your cases.   If you are looping cases, that is an ever growing list.

Regards
Andrew