There is no transparency to identify the total time taken for an agent to work on a particular case and which type of inbound enquiries has the highest rate of neglect from a single agent.

Simply subtracting the case open date from the case closed date won’t provide us with the information we are after because this is limited to the lifetime of a case from opened to closed. In addition, it will not indicate the number of users who opened the case.

I contacted Salesforce support to see if I whether there was a component that could achieve what I was after before investing time into building this, however to no avail.

The build

There are two requirements to this:

  • A custom object ‘time log’ to capture the duration
  • A Visualforce component that logs the start and end time each time a record is viewed

We firstly create a custom object with lookup fields to the record you wish to track the duration for, in this instance we will use the Case standard object. Next we create a number field in the new custom object to store the duration.

We will use JavaScript in conjunction with Visualforce to log the duration. Below is what the Visualforce page looks like.

<apex:page standardController="Case">

<script src="/soap/ajax/37.0/connection.js"></script>
<script src="/soap/ajax/37.0/apex.js"></script> 

<script type="text/javascript">
var timerStart =;

window.onbeforeunload = function(){
    var timeObj = new sforce.SObject("Time_Log__c");
    timeObj.case__c = "{!}";
    timeObj.Sec__c = (;
    var tmp = [timeObj];


As simple as that! In the Visualforce page, we define a start time when a user opens the page, and create the custom object Time Log when the window/tab is closed by the user.

However, this is only compatible with standard page, it would not work properly in the service console, because we are technically not closing a ‘window’, but a sub-tab within a window.

In the next article, I will explain how it can be solved by using the integration tool provided by Salesforce and how we can report on agent performance with this object.