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
milan mohantymilan mohanty 

How to write trigger to count it's child?

I have a custom field on Account called CountChild__c, so now I want to write a trigger on Account to count it's related contacts and update that fild  CountChild__c, so if a Account will have 3 Contacts then that CountChild__c field on Account should be update with the value 3. How can I achove it through trigger? Please guide me. Thank you.
Vamsi KrishnaVamsi Krishna
Milan,
first thing, you need to write the trigger on Contact object and not Account object..
next, there are heaps of blogs and previous solved answers with actual trigger code for the same purpose..

references :
http://www.infallibletechie.com/2013/09/trigger-to-count-number-of-contacts.html
https://developer.salesforce.com/forums?id=906F000000093azIAA