Cage Flow Template

Calculate Case age based on business hours using Flow template

Cage flow template is a template in which we are able to calculate the duration for each status of the Case record considering business hours of the user. Business hours is a standard object in Salesforce. There is a lookup field present from Case object to Business hours. When the status of the Case is changed, a status duration record (Custom object- child of Case object) is being created with the same status value. You can see total business hours spent in the “Status Duration Time” field. When the case is “Closed”, then no other status duration record is created, only the previous record is being updated. We have made this whole process with the help of flow, apex and process builder. Here business hours play an important role in the calculation of the “Status Duration Time” field, which is calculated with the “Status Start Time” field and the “Status End Time” field. There are four cases according to which Status Duration Time field value is calculated:

  • When the Status Start Time and the Status End Time both come under business hours.

  • When the Status Start Time and the Status End Time both do not come under business hours.

  • When the Status Start Time comes under business hours but the Status End Time does not come under business hours.

  • When the Status Start Time does not come under business hours but the Status End Time comes under business hours.

    Cage Flow Template image1

Figure 1: Business hours setup in the org.

You can download the template through the link.

Automation Overview:


  • When the Case meets the criteria, the Process “Status Duration Process” is triggered.
  • Flow checks to see if it’s an existing open Case.
  • Flow updates the open existing record.
  • Flow checks to see if the case is still open or closed.
  • If Case is open, flow creates a new record in the custom object Status Duration.
  • If the case is closed, flow exits.

    Cage Flow Template image2

Figure 2: Changing the state of the Case updates the Status Duration record.

You can also refer to the User Manual for more details about the template.