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

correct data is not showing in the field First_Response__c
this is my helper class:-
public class CaseTriggerHelper {
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 firstResponce(){
BusinessHours defaultBH = [ SELECT Id
FROM BusinessHours
WHERE IsDefault = true Limit : 1
];
for(Case caseObj : newCases ){
if( (caseObj.First_Response__c == Null)
&& UserInfo.getUserId() == caseObj.OwnerId ){
Decimal result = BusinessHours.diff(defaultBH.Id, caseObj.CreatedDate, caseObj.LastModifiedDate );
Decimal resultingHours = result/(60*60*1000);
caseObj.Helper_First_Responce__c= resultingHours;
Decimal HH = resultingHours.round(System.RoundingMode.DOWN);
Decimal tempMM = ( resultingHours - resultingHours.round(System.RoundingMode.DOWN)) * 60;
Decimal MM = tempMM.round(System.roundingMode.DOWN);
Decimal SS = (( tempMM - tempMM.round(System.RoundingMode.DOWN)) * 60).round(System.roundingMode.DOWN);
string finaltime = ''+HH+':'+MM+':'+SS;
caseObj.First_Response__c=finaltime;
}
}
} now i have a requirement to populate the time between when case is opned and its first responce in the field First_Response__c in HH:MM:SS .now the issue is when i create a new case it shows 0:0:0 in First_Response__c rather than showing some time in the field
like some seconds like0:0:12 .
how i fix this issue?
any suggestions?
public class CaseTriggerHelper {
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 firstResponce(){
BusinessHours defaultBH = [ SELECT Id
FROM BusinessHours
WHERE IsDefault = true Limit : 1
];
for(Case caseObj : newCases ){
if( (caseObj.First_Response__c == Null)
&& UserInfo.getUserId() == caseObj.OwnerId ){
Decimal result = BusinessHours.diff(defaultBH.Id, caseObj.CreatedDate, caseObj.LastModifiedDate );
Decimal resultingHours = result/(60*60*1000);
caseObj.Helper_First_Responce__c= resultingHours;
Decimal HH = resultingHours.round(System.RoundingMode.DOWN);
Decimal tempMM = ( resultingHours - resultingHours.round(System.RoundingMode.DOWN)) * 60;
Decimal MM = tempMM.round(System.roundingMode.DOWN);
Decimal SS = (( tempMM - tempMM.round(System.RoundingMode.DOWN)) * 60).round(System.roundingMode.DOWN);
string finaltime = ''+HH+':'+MM+':'+SS;
caseObj.First_Response__c=finaltime;
}
}
} now i have a requirement to populate the time between when case is opned and its first responce in the field First_Response__c in HH:MM:SS .now the issue is when i create a new case it shows 0:0:0 in First_Response__c rather than showing some time in the field
like some seconds like0:0:12 .
how i fix this issue?
any suggestions?
Are you using the before trigger here, because I do not see you are updating the Case . If you will use the before trigger then CreatedDate and Lastmodified Date would be null, cause of that you are receving 0: 0: 0. Just to verify, I tried of writing sample code and checking the data using debug log and I have got the correct date time in my logs, refer the following code to update your class:
Mark my anser as solved if it does help you.