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

How to Calculate the Case Age considering Salesforce Business Hours using schedule Apex?
global class ScheduledApexOnCase implements Schedulable { global void execute(SchedulableContext sc) { Date today = system.today(); Decimal caseAge; List<case> newCaseList = new List<case>(); BusinessHours stdBusinessHours = [select id from businesshours where isDefault = true]; newCaseList = [Select id, CreatedDate, Status, CaseAge__c from Case]; //CaseAge__c is a Text field for(Case eachCase: newCaseList) { if(eachCase.Status != 'Closed') caseAge = BusinessHours.diff(stdBusinessHours.id, eachCase.CreatedDate, today) / 1000 / 3600; else caseAge = BusinessHours.diff(stdBusinessHours.id, eachCase.CreatedDate, eachCase.ClosedDate) / 1000 / 3600; eachCase.CaseAge__c = String.valueOf(caseAge) + ' hours'; } update newCaseList; } }
Here iam getting Compile Error: Illegal assignment from String to Decimal at line 16 column 9, How to solve the above scenario please give me some ideas
eachCase.CaseAge__c = caseAge;
you cannot append string to a number field.
So if the difference is 2,5 hours, the field is filled with 150 minutes.
What do i have to change in the code to realize this ?