How to count the numbers of Open and Closed tasks on an account in Salesforce?

Wouldn’t it be great if you could use a trigger to keep count of all the open and closed tasks on an account in Salesforce? Today, in this blog, we will share a trigger code that will count the open and closed activities on a Salesforce account. The counts on the parent objects triggered by the code will allow admins/developers to automate the business processes quickly.

So, without any delay, let’s begin!

Salesforce Apex Trigger to count the numbers of open and closed tasks on an account

To create the Apex trigger, you will need to create two custom fields on Account. One is an Open Task Field and the other is a Closed Task Field.

Now, use the code below to create the trigger.

Code

Conclusion

There you have it! Try out the solution and share your feedback with us at HIC Global Solution! If you want to receive more such helpful Salesforce Development solutions, stay tuned to our blogs. Happy Coding!

Our Location worldwide
India
3rd Floor, A-10, Pegasus Tower, Sector 68, Noida, Uttar Pradesh 201301 +91-1203117884
SR Tower 2nd Floor Hydel Gate Haldwani Uttarakhand 263126 +91-5946359996
USA
333 West Brown Deer Road Unit G – 366 Milwaukee WI, USA 53217 +1(262) 310-7818
UK
7 Bell Yard, London, WC2A 2JR +44 20 3239 9428
Canada
HIC Global Solutions INC
43 Lafferty Lane, Richmond Hill, L4C 3N8, CA +1(262) 310-7818