You need to sign in to do that
Don't have an account?

Rollup Summary field for Lookup relationship
I have two standard objects Quote and Order. There exists a lookup relationship between these two. I have a field on Order called Milestone_Amount__c and a field on Quote called Cumulative_Order_Value__c.
On insert, this field on Order will be blank. But I need an after update, after delete, after undelete trigger to rollup the sum of this field on order to the cumulative field on quote. Can someone help me?
I'm not very familiar with Apex Code development.
Thanks
On insert, this field on Order will be blank. But I need an after update, after delete, after undelete trigger to rollup the sum of this field on order to the cumulative field on quote. Can someone help me?
I'm not very familiar with Apex Code development.
Thanks
Roll-Up summary fields are a great way to perform calculations on a set of detail records in a master-detail relationship. For instance, if you have a sales order you can create a roll-up summary field to display the sum total of all sales order items (related detail records) for the sales order. The one drawback regarding roll-up summary fields is that they only work for master-details relationships. If you have a lookup relationship to your detail records from your sales order, then roll-up summary fields are not available.
So how do you perform this same type of functionality if you only have a lookup relationship? I ran across this same problem while doing some non-profit work for Medisend International and the solution (with a caveat) is to write a trigger to perform the roll-up.
Medisend ships medical products overseas to developing countries. Medisend has a Shipment custom object that has a related list of Inventory Items which are the actual products on the shipment. In their scenario, the Inventory Items cannot be a master-detail relationship since these items can live on their own until they are assigned to a shipment. So to display the total number of items on the shipment to the case managers, I created a numeric filed on the shipment and wrote a trigger to sum the total number of items assigned to the shipment each time an Inventory Item is added or removed from the shipment.
However, there is one caveat due to governor limits. If the shipment contains more than 1000 items, then the trigger will throw an error at line 19 below. This is due to governor limits specifying that a List can only contain 1000 records. There is an Idea regarding this functionality so please vote for it. However if you are confident that your collection will never contain more than 1000 records, this solution should work for you.
Please find the sample code below and modify it as per your requirement.
Apex Class: Test Class:
For more information on this please refer to the below links.
https://github.com/abhinavguptas/Salesforce-Lookup-Rollup-Summaries
https://andyinthecloud.com/2013/07/07/new-tool-declarative-rollups-for-lookups/
Please mark this post as solved if it helps.
Best Regards,
Nagendra.P
I recently tried this - https://www.youtube.com/watch?v=hNCBJi-Nys0