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
Saravana RavikumarSaravana Ravikumar 

I have a standard object that needs to have an amount rolled up from a custom object that is in a lookup relationship. To achieve this , Can I write a trigger on the child object ?

Arun Kumar 1141Arun Kumar 1141
Hi @Saravana,

Yes you can certainly write the trigger on the child object in order to get the amount rolled up. In this you can use the AggregateResult Datatype in order to roll up the amount. 
 
List<AggreagateResult> agList = [Select SUM(Amount),ParentObjectId from Custom_Object__c GROUP by ParentObjectId];

 However I suggest you to go for the Roll Up Summary field to achieve the desired functionality. 

Hope this helps.

Thank you.