You need to sign in to do that
Don't have an account?
atharva Vispute 3
can anyone help to solve this problem??
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));
}
}
}
}
I am gertting error last line..
Illegal assignment from Long to Datetime
this is the error i am getting.. please help me to solve this querry.. and plzz provide me correct code
Thank you!!
//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));
}
}
}
}
I am gertting error last line..
Illegal assignment from Long to Datetime
this is the error i am getting.. please help me to solve this querry.. and plzz provide me correct code
Thank you!!
ts.Actual_Time__c=(system.now().getTime()-ts.TaskOpened__c.getTime()/(1000*60*60));
According to this doc - https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_datetime.htm#apex_System_Datetime_getTime, return type of getTime() is "Long". I am assuming that the Actual_Time__c field is of type DateTime. That is the reason why the compiler can not assign a Long value to the DateTime field.
Can you check if Actual_Time__c is of type Number and
TaskOpened__c is of type Date/Time.
This might be causing the issue
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
Both actual time and task opened fields are of datetime data type.. plz provide me correct line of code.
Thanks!!
As the field should capture the differenece of datetime fields it will capture in Hours .
Thanks,
So what can I do now? Please provide me correct line of code
Thanks!!