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
TanuTanu 

Roll up summary

Hi All,

I have created a lookup relationship between opportunity and oap__c..  now i want to calculate sum(amount) of all those opportunities which is linked with a particular oap. I created the lookup field OAP on opportunity. As per my understanding this cant be done through configuration.

Could you please help how can i acheive this.?? I am new to apex trigger pls help.

Thanks
Tanu
Alain CabonAlain Cabon
Hi,

The relationship must be of type master-detail (not lookup) for roll up summaries.

Each custom object can have up to two master-detail relationships and up to 25 total relationships.
https://help.salesforce.com/articleView?id=overview_of_custom_object_relationships.htm&type=0

Trailhead: Since roll-up summary fields are based on master-detail relationships, it’s useful to review object relationships before creating a roll-up summary field.

https://trailhead.salesforce.com/en/modules/point_click_business_logic/units/roll_up_summary_fields

Andrew Fawcett has developed this alternative (a widely-used tool as many Andrew Fawcett's tools) 

Declarative Rollups for Lookups!   Rollup information between Lookup relationships not previously possible without writing Apex Triggers
https://github.com/afawcett/declarative-lookup-rollup-summaries

Regards
Alain CabonAlain Cabon
Another alternative with constraints to triggers are flows:

Roll-Up Summary for Account Fields (Part 1)​ : Flows are triggered by Process Builder and that limits them from triggering BEFORE they are deleted.  So, if your company is deleting Accounts and Opportunities often, then you might need to build a recalculate button (coming soon!).

https://salesforcesidekick.com/2015/03/23/flow-roll-up-summary-for-account-fields-part-1/

https://salesforcesidekick.com/2015/03/23/not-your-typical-flow-roll-up-summary-for-account-fields-part-2/

Few people are confortable with the flows but it is an alternative zero code (no apex) with some strong constraints that could work.

Regards