+ Start a Discussion

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.



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.