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
gregj777gregj777 

Roll-up summary on custom object

Can someone help me with a simple apex trigger on a custom object? I need to be able to sum up the Total price on a list of opportunity products in a opportunity. Here's a scenario:

 

Opportunity {Customer A} Package 10 Events(Products)

Opp Product - Event 1

Opp Product - Event 2...and so on

 

Opportunity {Customer B} Package 10 Events(Products)

Opp Product - Event 1

Opp Product - Event 2...and so on

 

Event (custom object)

Event Summary = Event 1 + Event 2

 

Ideally I would like to manage this under Campaign object but that doesn't seem to work.

 

 

 

yvk431yvk431

Not very clear with your requirement.

 

You wanted to sum the Total Prices of Opportunity Products, we already have a stanard rollup field 'Amount' on Opportunity.

Even if we wanted to include any custom criteria, you can just go for a Rollup Summary field.

gregj777gregj777

Here's a clearer example:

 

Create opportunity for a Account that includes a Package of products and each product is tied to a Campaign. How can I do that so it shows the total amount that was sold on that product from the Campaign.

 

Account A --> Opportunity A ---> Package A(10 products) ---> Product Items 1, 2, 3, 4, etc. 

Account B --> Opportunity B ---> Package A(10 products) ---> Product Items 1, 2, 3, 4, etc.

 

Campaign ---> Opp A Product Item 1 + Opp B Product 1 = Total Amount. 

 

I can't use the standard Campaign statistics becuase I'm tying the Campaign by Product item. I am trying to prevent having the user create 10 Opportunities if they purchase a Package of 10 products. 

 

The real life scenario this is used in is for a Events Management company where a Customer purchases a package fo 10 events and the event(product item) is tied to a (event) Campaign.

 

Any other solutions? 

 

dmchengdmcheng

This blog post should give you most of what you need:

http://www.anthonyvictorio.com/salesforce/roll-up-summary-trigger/

 

Note there is a hidden bug in his method - if there is only one payment for an opp and you delete it, the total is not recalced.  See my comment at the end of his post.

gregj777gregj777

O.k. that kind of makes sense. I have simplified the process a little better. So I am tying a bunch of opportunities to a Contract. So I want to be able to sum the opportunity amount and count under the contract object. Issue you can't use the Roll-up function is that old master-detail relationship. So could I copy and paste this trigger under the contract object and update it with the appropriate fields?

I created a currency field called "TOTAL OPPORTUNITY AMOUNT".