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 

Create an apex trigger which will calculate the Actual time taken to close the Task form the time its Status is “New” to the time status is changed to “closed” and save the value in Field “Actual Time”

can anyone have solution for this
 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

We may require an another field to track the time when the status is "new" so we can calculate the time between this and closed  status. Are you okay with creating datetime field .

It is not required for the above field to be shown in the pagalayout as it is not needed.

Thanks
 
atharva Vispute 3atharva Vispute 3
which field I have to create then
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Atharva,

You have to create field of datetime to store the datetime when the status is "new".

Are you okay with creating new field?

Thanks,
 
atharva Vispute 3atharva Vispute 3
done. I have just create a new date/time field
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

Do you want the difference in hours or minutes or days. Can you confirm on it.

Thanks,
 
atharva Vispute 3atharva Vispute 3
wait I will send you the full question
atharva Vispute 3atharva Vispute 3
  1. Create an apex trigger on task tracker which will calculate the Actual time taken to close the Task form the time its Status is “New” to the time status is changed to “closed” and save the value in Field “Actual Time”
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Atharva,

You can try below apex trigger. This will give the number of hours between new and closed(Completed).

As i asked to create field of type datetime. I have created field TaskOpened__c .
trigger TaskTimeCalculation on Task (before insert,before update) {
    
    if(Trigger.isinsert && Trigger.isbefore)
    
    for (Task t:Trigger.new){
        if(t.status=='New')
            t.TaskOpened__c =system.now();
    }
    
    if(Trigger.isupdate && Trigger.isbefore){
        for(Task ts:Trigger.new){
        
        Task oldtask= Trigger.oldmap.get(ts.id);
            
            if(ts.Status=='New' && oldtask.Status!='new'){
                ts.TaskOpened__c=system.now();
            }
            
            if(ts.Status=='Completed' && oldtask.Status!='Completed' && ts.TaskOpened__c!=null ){
                
                
             ts.Actual_Time__c=(system.now().getTime()-ts.TaskOpened__c.getTime()) /(1000*60*60);
            }
            }
    }

}
Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
atharva Vispute 3atharva Vispute 3
5 errors I am facing.. Does not find variable TaskOpned_C
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Atharva,
The API name of the nanme is having issue it should be __c not _c. Can you chcck and update it.

Thanks,
 
atharva Vispute 3atharva Vispute 3
same API no but still facing this issue
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Atharva,

Can you replace TaskOpned_C with TaskOpned__c and try

Thanks,
'
atharva Vispute 3atharva Vispute 3
see my erorrs

User-added image
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

Is this on Task__c object and can you confirm if the field TaskOpened__c is created on it (Activity object).

Thanks,
 
atharva Vispute 3atharva Vispute 3
yes i have already created TAskOpened field
 
atharva Vispute 3atharva Vispute 3
can you help mi to solve this problem

Create workflow on Project which will check if the stagename is in “In Progress” for more than 12 days wrt Start date than change the status to “Close lost” and populate the End date as todays date
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Atharva,

This seems to be other question. Can you post it as other question so it helps others who reviews teh question.

Thanks,