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
Sia Thripio 4555Sia Thripio 4555 

"Write a trigger that counts the number of completed tasks on an account record and display the count in a custom field on Account record."

Best Answer chosen by Sia Thripio 4555
Abhishek BansalAbhishek Bansal
Hi Sia,

You can follow the below steps:
  1. Create a trigger on Task object. Context would be after update
  2. If the status is changed to Completed, store the related account id in a set.
  3. Query the account records along with the child tasks where status is equal to Completed.
  4. Now set the custom field = related tasks size.
  5. Update the account.
Let me know if you need any help with the trigger code.

Thanks,
Abhishek Bansal.
Gmail: abhibansal2790@gmail.com
Skype: abhishek.bansal2790
Phone: +917357512102