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
Patrick Marks 2Patrick Marks 2 

calculate total value of related opportunities in custom opportunity field

Hi everyone-I have an interesting business case, so will try to keep this as concise as possible:

We have a business unit (Investor Services) with 2 Opportunity record types, called Firm (parent opportunity) and Fund (child opportunity). I created a lookup relationship on the Opportunity object that also looks up to Opportunities. Opportunities of the Fund record type (child) are required to have a value in the lookup field that points to the parent opportunity (Firm).

Here is what I'm trying to solve for: we have a custom Currency field on the Firm record type called Total Contract Value. What I am trying to do is write a trigger that will calculate the sum of all Closed Won Fund opportunities (children), plus the amount of the Firm opportunity (parent), assuming it is Closed Won as well. Would love some direction on what this trigger would look like. Thanks in advance!