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
AsitAsit 

Trigger to Retrieve value from child object and update a field in parent

I am a novice apex programmer and new to triggers. Please suggest me how can I write a trigger to fetch a value from Child__c object having a field named "No_of_child_count__c" and populate the same calue in Parent__c object having a field named "Count_parent__c".

We just need to update the parent field after insertion of new records in child object.

 

Damien_Damien_

You would need to query for any of the children that share a parent.  I would use a Map of Lists so that you can grab all of the children of a specific child object.  You can then just do a list.size() to add up the number of children in a single call.  Good luck on this start.