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
ryepes15ryepes15 

How to create a sum field off formula field

I have an opportunity that is tied to a contract. An opportunity can have many contracts. The contract is tied to a custom object called Operative one orders . on the Operative one order there is a field called Order Amount. There could be multiple Operative one orders to one contract. I have a field on the contract that sums all the order amounts I need to create a field on the opportunity that sums all the order amounts on the contract(s)
Deepak GulianDeepak Gulian
It seems trigger could be the only option you left with, since the field that calculate the sum of all the order amount on Contract object must be Rollup type and you can't use another Rollup Summary to calculate the sum of Roll up field.
jigarshahjigarshah
Since Opportunity and Contracts have a Lookup relationship between them hence you would be unable to create a Rollup Summary field to cacluate the sum of all Order Amount values on Contracts for a given Opportunity Record. Here are the options that could prove helpful

1. You could implement a custom solution using a Apex Trigger that iterates through all the Contracts for a given Opportunity whenever a Contract associated with an Opportunity or the Opportunity itself is modified. Considerations of this approach

Pros
  • Flexibility to implement custom business logic
  • Complete control over the behaviour of summation for e.g. you could implement a filtered summation logic to sum only those contracts which are active.
Cons
  • Increased go to market time due to custom development
  • Additional effort required to implement test code with adequate test code coverage for the implemented code which is mandatory for a production release.
  • Multiple triggers on the same object and the same event could lead to unpredictable output due to no control on the trigger execution precendence.
2. You could leverage a third party Appexchange tools to help accomplish this. The following tools should help you accomplish your given requriement. Pros
  • Ready to use solution
  • Reduced go to market times
Cons
  • Limited flexibility and control
  • Dependency on the package provider in case of issues
Please do not forget to mark this thread as SOLVED and answer as the BEST ANSWER if it helps address your issue.