function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
atharva Vispute 3atharva Vispute 3 

can anyone tell me the solution for this error

User-added image
AnkaiahAnkaiah (Salesforce Developers) 
Hi Atharva,

You were trying to assign number value to dateTime data type.

can you change the Actual_Time__cfield to time datatype.

Thanks!!
atharva Vispute 3atharva Vispute 3

Hi Ankaiah,
Ok I will do it and then inform you.

Thanks!!
atharva Vispute 3atharva Vispute 3
Hi Ankaiah,
there is still an error
Thanks!!
AnkaiahAnkaiah (Salesforce Developers) 
What is the error??
atharva Vispute 3atharva Vispute 3
still the previos error continues on the screen
 
AnkaiahAnkaiah (Salesforce Developers) 
Can you share the code. I will try from my end and get back to you.

Also mention the data type of the fields you were updating in the trigger.

Thanks!!
atharva Vispute 3atharva Vispute 3
trigger TaskTimeCalculation on Task_Tracker__c (before insert,before update) {
    
    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);
            }
            }
    }

}
Monu Sharma 9Monu Sharma 9
Hi @atharva Vispute 3

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!!