In Customer Support you might get a ticket that comes in Friday afternoon, and doesn’t get worked on until Monday morning. While your Support Team only actually spent 5 minutes working, the basic Case Age calculations tell us that it took almost 3 days! So, the problem we are going to be solving is how to find out the actual ‘time worked’ on the Case. You’ll see at the end of this post how we could easily make this more complicated by tracking the Status, Owner, and other Case Fields on “START” and on “END” of working on a Case, but for now lets keep it simple!
If you’re interested in just having better Case Age tracking, make sure you also check out this post: How to track the Case Age of each Status. There is even an Unmanaged Package for you in the Packages tab!
Before we can start building the Flow, we must get everything built. We need to create a new Custom Object with a few Custom Fields and a Roll-up Summary Field on the Case.
First lets navigate to the Custom Objects page (Setup | Create | Objects)
Second, lets create a New Custom Object
Next, we need to fill out the information for our Object. The keys to this is to make sure you are doing an Auto Number for the Data Type of the Record’s Name. I typically check everything under the Optional Features and Object Creation Options, its always easier to just remove it after creation if you need to.
Ok great! Now our Object is created. But, we need to create some Custom Fields to hold the data that we are trying to track. For this post, as I mentioned at the start, we are only dealing with the Time. If you want to get advanced and track other fields from the Case, you can easily do that!
Now, as you can see we have a field called “Minutes” here that is a Formula (Number; 16,2). So lets take a look at what is going on inside of that field and how we are making a Date/Time field into a Minutes calculation.
( End_Time__c - Start_Time__c ) * 1440
Awesome, we are now done with our Custom Object! We need to go navigate to our Case Object and create a Roll-up Summary Field to summarize our Minutes from the Time Tracking Object we just created. This way we can see the running total of all Users that worked on the Case. If we want to view reports based on individuals, we would simply need to run a Time Tracking report or look at the Related List.
Great, now that we have gotten the formalities out, we can get into the good stuff. So, lets begin by navigating to the Flow (Setup | Create | Workflows & Approvals | Flows)
Then, hit “New Flow”
Now here is where all the fun starts! We are going to knock out two birds with one stone, and combine our Start and End Buttons into just ONE Flow.
Lets start our Flow off with a Record Lookup. In this Lookup we will be searching to see if there is already an open Time Tracking record. This will help us determine if the clicks on our Buttons are valid, or if they were accidental. So, we want to search for a Record from the Running User that has a Start Time, but does not have an End Time, which means they are still Open.
Now we need to create two variables to help us setup our Filtering. First we will create a Text Variable called “var_CaseId” and then we will create a Text Variable called “var_UserId”.
Now lets finish adding our Lookup criteria in using those variables that we just created.
Now that we have our criteria set, lets assign the Id of the record we may or may not find to be referenced in our Flow. To do this, we will need to first create the new Text Variable “var_TimeTrackingId”.
When we set the Id to be this variable, make sure you check the box to assign null values if no record is found.
Lastly, we need to set this as our Start element!
Now, lets determine if our Buttons being clicked was intentional or not. For instance, if we are clicking from the Start Button, we want to avoid creating a duplicate or extra record.
For our first Outcome, lets determine if the Start Button was pressed, and if there is NOT an existing Time Tracking record for this Running User. To do this, we will see if our var_Start was populated on the click, and if var_TimeTrackingId is null. If both of these are true, we want to pass the Flow
For our second Outcome, lets determine if there is an existing Time Tracking record for us to upload. If there is, we know it was a valid click, and we can proceed to updating the Time Tracking record. To do this, we will see if our Record Lookup found a value. Also, we want to make sure that this didn’t come from the Start Button being clicked, so lets filter on that variable as well.
To finish, change your Default Outcome to “No”. We will not connect “No” to anything, because it means that the click was accidental.
Alright, now we need to setup the Record Create for our “Start” Button being clicked. So lets grab the Record Create element and search for our Time Tracking Object.
Now, lets determine what our New Record will look like. We want to map our UserId, CaseId, and the current Date/Time to the new Time Tracking record. For creating the Start Time value, we want to use the SYSTEM field “$Flow.CurrentDateTime”.
Because we are not referencing this variable any further in our Flow, we can ignore filling out the “Assign the record ID” section of this Record Create element.
Now lets connect the Start Button Pressed Outcome to our Record Create.
Great job, lets now create our Record Update to add the End Time to the Time Tracking record if the End Button was pressed. For this, we will once again search for the Time Tracking Object, search for when the Id equals our “var_TimeTrackingId”. We then want to update the “End Time” field with the current Date/Time. We will do this again using the SYSTEM field “$Flow.CurrentDateTIme”.
Now, to finish this off, lets map our Decision element to this Record Update for our End Button Outcome.
Now, the only thing left for us to do is create a FAULT Screen in case something errors. We don’t want to confuse our Users. To do this, we simply add a Display Text field to our Screen, and then type in our Fault Message. After you’ve created this Screen, connect your Faults on your Record Lookup/Create/Update to the Screen. Since this is not an Autolaunched Flow, we can keep this screen here as we Save.
Congrats! We are done with our Flow. Lets Save the Flow.
Now that we have our Flow saved, lets navigate back to our Flow Detail page and do two things. First, lets activate our Flow. Second, lets grab the Unique Name (or URL) and get ready to use it in our Buttons!
Now, we’ve Activated our Flow and know what our URL is going to be, lets build our our Buttons! Lets start with the Start Button since this will be the tricky one.
First, lets navigate to the Case’s Buttons, Links, and Actions page (Setup | Customize | Cases| Buttons, Links, and Actions). From here, we will select the New Button or Link. If you are new to Buttons, take a look at my previous posts, Choosing your Button and Writing a Button’s URL.
Awesome, now lets update our Button URL. We want to select Detail Page Button for the Display Type, Display in existing window without sidebar or header for our Behavior, and URL for our Content Source. In the URL, we want to pass in a value to the “var_Start” variable, so that we can know which Button is being clicked. In this situation, I am passing the value “1” into the variable.
Now that we got our Start Button finished, we are going to do the exact same thing but remove the “&var_Start=1” part of our URL.
Click Save, and you are done! Now you can add the Buttons to your Page Layout and start tracking your time!