The statement 'system.now().getTime() - ts.TaskOpened__c.getTime()' will return the milliseconds which is the type of Double and you are assigning it to DateTime type field. Change Actual_Time__c field to double type if you really need to calculete it in milliseconds.
You were trying to assign number value to dateTime data type.
can you change the Actual_Time__cfield to time datatype.
Thanks!!
Hi Ankaiah,
Ok I will do it and then inform you.
Thanks!!
there is still an error
Thanks!!
Also mention the data type of the fields you were updating in the trigger.
Thanks!!
if(Trigger.isinsert && Trigger.isbefore)
for (Task_Tracker__c t:Trigger.new){
if(t.Status__c=='New')
t.TaskOpened__c =system.now();
}
if(Trigger.isupdate && Trigger.isbefore){
for(Task_Tracker__c ts:Trigger.new){
Task_Tracker__c oldtask= Trigger.oldmap.get(ts.id);
if(ts.Status__c=='New' && oldtask.Status__c!='new'){
ts.TaskOpened__c=system.now();
}
if(ts.Status__c=='Completed' && oldtask.Status__c!='Completed' && ts.TaskOpened__c!=null ){
ts.Actual_Time__c=(system.now().getTime()-ts.TaskOpened__c.getTime()) /(1000*60*60);
}
}
}
}
The statement 'system.now().getTime() - ts.TaskOpened__c.getTime()' will return the milliseconds which is the type of Double and you are assigning it to DateTime type field. Change Actual_Time__c field to double type if you really need to calculete it in milliseconds.
Thanks!!