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
Linda 98Linda 98 

URGENT!! Update count on deleting records.Using delete context variable.

Hi i am having a requiremnt where i have to update custom fields which hold count of tasks on that Case.
Everything works fine but when i delete the task,i want the count to be updated/decreaded accordingly.
If i am having 8 open tasks and when i delete one task of it,i want the custom field to be updated with 7 .
please guide me.
 
sagar Vadariya 5sagar Vadariya 5
Write a trigger under Task object of "after insert", "after Update", "After Delete". 
1-> Get the id of Parent case for that task based on "Related To" Field of Task.(this will give you the case Id)
2-> Use the case id to query all the open tasks related to that case Id.(select count() task where status=open AND relatedto ='Case ID which we got in 1st step')
3-> set the count value which we received in 2nd as task count in that case record.  

This logic will be aplicable for all the event insert ,update and delete and you would not need to worry about handeling them seperatly 
Nishant Dubey 7Nishant Dubey 7
write a trigger using trigger trigger_name(before insert , before update ,before delete) why "before" because you are changing the count value
Please check