You need to sign in to do that
Don't have an account?

need to measure how long time between when the Case was opened and when it was first responded.
hi all,
I need to create a way to capture when the first response. I then need to measure how long time between when the Case was opened and when it was first responded.
I created two fields:
Time_to_First_Response__c
First_Response__c
I need to capture the first response and measure the time to first response in a trigger .
First Response is defined as when the case owner user makes any edit to the case or logs an activity against the case.
Time to First Response Calculation:
I need to NOT include when office is closed (nights, weekends, holidays) in calculation.
public class CaseUpdateResponseTriggerHelper {
public static List<Case> newCases = new List<Case>();
public static List<Case> oldCases = new List<Case>();
public static Map<Id, Case> newMapCases = new Map<Id, Case>();
public static Map<Id, Case> oldMapCases = new Map<Id, Case>();
public static void updateFirstResponse(){
List<Case> Cases = [SELECT id, First_Response__c, Time_to_First_Response__c FROM Case];
datetime firstresponce;
for(Case c: newCases){
if(c.createddate == oldMapCases.get(c.id).lastmodifieddate && c.First_Response__c == Null ) {
decimal miliseconds = decimal.valueOf(system.now().getTime() - c.createddate.getTime());
Integer seconds = integer.valueof(miliseconds / 1000);
Integer Minutes = integer.valueof(seconds / 60);
Integer Hours = integer.valueof(Minutes / 60);
Integer Days = integer.valueof(Hours / 24);
if(seconds >= 1 && Minutes <= 0){
c.First_Response__c = datetime.valueof(seconds);
}else if(Minutes >= 1 && Hours <= 0){
c.First_Response__c = datetime.valueof(Minutes) ;
}else if(Hours >= 1 && Days <= 0){
c.First_Response__c = datetime.valueof(Hours) ;
}else if(Days >= 1)
c.First_Response__c = datetime.valueof(Days) ;
}
}
}
} how to do it with business hours?
any suggestions?
please provide me solution with business hours
I need to create a way to capture when the first response. I then need to measure how long time between when the Case was opened and when it was first responded.
I created two fields:
Time_to_First_Response__c
First_Response__c
I need to capture the first response and measure the time to first response in a trigger .
First Response is defined as when the case owner user makes any edit to the case or logs an activity against the case.
Time to First Response Calculation:
I need to NOT include when office is closed (nights, weekends, holidays) in calculation.
public class CaseUpdateResponseTriggerHelper {
public static List<Case> newCases = new List<Case>();
public static List<Case> oldCases = new List<Case>();
public static Map<Id, Case> newMapCases = new Map<Id, Case>();
public static Map<Id, Case> oldMapCases = new Map<Id, Case>();
public static void updateFirstResponse(){
List<Case> Cases = [SELECT id, First_Response__c, Time_to_First_Response__c FROM Case];
datetime firstresponce;
for(Case c: newCases){
if(c.createddate == oldMapCases.get(c.id).lastmodifieddate && c.First_Response__c == Null ) {
decimal miliseconds = decimal.valueOf(system.now().getTime() - c.createddate.getTime());
Integer seconds = integer.valueof(miliseconds / 1000);
Integer Minutes = integer.valueof(seconds / 60);
Integer Hours = integer.valueof(Minutes / 60);
Integer Days = integer.valueof(Hours / 24);
if(seconds >= 1 && Minutes <= 0){
c.First_Response__c = datetime.valueof(seconds);
}else if(Minutes >= 1 && Hours <= 0){
c.First_Response__c = datetime.valueof(Minutes) ;
}else if(Hours >= 1 && Days <= 0){
c.First_Response__c = datetime.valueof(Hours) ;
}else if(Days >= 1)
c.First_Response__c = datetime.valueof(Days) ;
}
}
}
} how to do it with business hours?
any suggestions?
please provide me solution with business hours
You could create a workflow to solve your issue. You could create a rule that only updates 'fist response' field if it is empty.
Let me know if this helps you.
Thanks