I need help to achieve the following:
When a Task priority is changed by a particular user, I must set a fixed amount of REAL (non-working) hours in a custom field in the same Task.
The purpose is to trigger and to send an e-mail alert to the task assignee after this fixed amount of REAL hours.
For each Task priority there is specific amount of working hours:
Urgent - 4 working hours
High - 8 working hours
Normal - 24 working hours
Low - 72 working hours
However I need the real hours.
For instance, when user select "Urgent" and the current date/time is Tuesday 17:00h, then I must set 4 working hours which means: 1 working hour from the current day (Tuesday) and 3 working hours from the next day (Wednesday).
Thus the end of the Task should be at 12:00h on Wednesday.
When calculated the REAL hours: from Tuesday 17:00h till Wednesday 12:00h there are 19 real hours.
I have to set this number 19 (REAL hours) into the custom field.
I also need to take the company working hours from the database table "BusinessHours" (each company may have different working week).
How can I calculate the REAL hours based on the selected Task priority?
Note: I have wrote an algorithm in apex which performs the mentioned calculations but...
1. If I invoke it from "beforeUpdate" trigger, then the new Task priority is not set (committed) yet.
2. If I invoke it from "afterUpdate" trigger, I have the new value but I can not make 'update' on the current Task (it is read-only because we are already in the update procedure/trigger).
Any help and appropriate suggestion is appreciated.