+ Start a Discussion
sieb4mesieb4me 

business hours apex error

I have this code below and logs show following errors, what can be the reason? Thanks.

cas.Email_Template_GCS_CallBack_Time__c = BusinessHours.addGmt (cas.BusinessHoursId, cas.CreatedDate, (cas.Email_Template_GCS_Call_back_time_Number__c * 60 * 60 * 1000L).longValue()).format('MMMM dd yyyy hh:mm a z');

See this error when i create case
Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger CaseBeforeInsert caused an unexpected exception, contact your administrator: CaseBeforeInsert: execution of BeforeInsert caused by: System.MathException: null: (System Code)

Log shows this

1:24:15.690 (690052735)|SYSTEM_METHOD_ENTRY|[841]|system.BusinessHours.addGmt(Id, Datetime, Long) 11:24:15.691 (691353829)|SYSTEM_METHOD_EXIT|[841]|system.BusinessHours.addGmt(Id, Datetime, Long) 11:24:15.691 (691363647)|METHOD_EXIT|[50]|01pZ0000000GXFv|UpdateCase.CalculateFieldsForTemplates(LIST<Case>) 11:24:15.691 (691383145)|CONSTRUCTOR_EXIT|[84]|01pZ0000000GXFv|<init>(Boolean,Boolean,LIST<Case>,LIST<Case>,MAP<Id,Case>,MAP<Id,Case>) 11:24:15.691 (691481029)|FATAL_ERROR|System.MathException: null (System Code) Class.UpdateCase.CalculateFieldsForTemplates: line 841, column 1 Class.UpdateCase.<init>: line 50, column 1 Trigger.CaseBeforeInsert: line 84, column 1 11:24:15.691 (691502049)|FATAL_ERROR|System.MathException: null




 
Best Answer chosen by sieb4me
sieb4mesieb4me
resolved this already by using system.today(), instead of cas.CreatedDate,