You need to sign in to do that
Don't have an account?
Tommy Sunderland 16
Calculate first response time on Opportunity (not Case) in minutes
Hello, I have an involved request that I'm hoping someone can help me solve.
Additional information:
- On Opportunities we track first response time, calculated by taking Date/Time that the first activity is logged (after the opportunity is created) and subtracting from it the Date/Time that the Opportunity was created. The difference between the two calculates a first response time in minutes.
- The team has asked me to take into account our business hours (9AM - 5PM) in this equation, meaning that if an opportunity is created after 5PM, then the first response time should only be calculated after 9AM the following morning. So an opportunity created at 5:00 PM on a Thursday and responded to at 9:15 AM Friday morning would show a first response time of 15 minutes (and not 960 minutes due to the off hours).
- Note: our current Default business hours are set to "24 Hours" and not to 9 to 5. We do not have separate business hours set in Salesforce for each office, just FYI
- Important note: We have multiple offices, so the proposed solution needs to take this into account.
Additional information:
- Someone pointed me to this solution, but this appears to account for hours, not minutes. I'm looking for minutes
- Someone else recommended customizing this package. The package is meant for Cases (I'm dealing with Opportunities). Additionally, I don't have great coding skils and I worry that the appropriate solution using this package may be beyond my skillset. However, I'm open to an advice.
When you want to take into account your business hours (9AM - 5PM), it is always a tricky problem because the "real" business hours take also into accounts the hollydays and the timezones.
The most accurate and "easy" solution is to use a trigger here.
One line of code is sufficient in Apex and all the details of business hours are take into account directly.
Double First_Response_Time = BusinessHours.diff(defaultBusinessHours.Id, opp.CreatedDate, OppMinEvtCreateddate)/3600000.0;
Use the BusinessHours methods to set the business hours at which your customer support team operates.
The remaining problems:
- You need two triggers: one for the events and one for the tasks (the same as above replacing just Event with Task)
- Only one definition of business hours has been used above (the default one) and that could be not sufficient.
- Each record of Case has its own BusinessHoursId but not the Event object. BusinessHours is closely linked with the cases.
- You must initate all the pre-existing opportunities for the First_Response_Time__c field (empty by default)
The initialization of the First_Response_Time__c field for all the opportunities is not difficult if you have the "dataloader" tool.How many events are there in your org?
1 minute = 60 seconds = 60 x 1000 milliseconds = 60,000 ms.
1 hour = 60 minutes = 60 x 60,000 ms.= 3,600,000 ms
Double First_Response_Time = BusinessHours.diff(defaultBusinessHours.Id, opp.CreatedDate, OppMinEvtStartdatetime)/60000.0;