0

We are capturing a few custom fields at product level and wanted to use them in some calculation. The result of the calculation needs appear on Opportunity custom fields.

Let us say, the product has field1 and field2 custom fields..I wanted to multiply these fields first and summarize this value for all products and update on opportunity(kind of rollup)

Example formula: SUM of all products(field1 * field2).

Having said that, I tried with workflow field update..I was able to get the custom field in workflow field update on OpportunityLineitem but I don't know how to to aggregate this for all products.

I was thinking trigger is the only option for this and here is the approach.

  1. Create a trigger on OpportunityLineitem which gets fired anytime a product added to Opportunity
  2. In the trigger do calculation based on the product custom fields and aggregate the value for all line items.
  3. Update opportunity.

Before moving forward, I wanted to make sure I am in the right direction OR it could be achieved with out a trigger using workflow field update or any other means.

Appreciate your feedback.

Thanks.

  • Guys, Any other comments? – sdondeti Sep 30 '14 at 18:14
1

I suggest following one of these two approaches:-

If the values in product are to be considered only at time, opportunity is created i.e. if values changes, then it has no impact to past opportunities

  1. Create fields (viz. X and Y) on opportunity product to persist these values (present in product)
  2. Create workflow to populate these fields (X and Y) on opportunityproduct creation, which will pull these field values from related products
  3. Create a third field Z on Opportunity line item, which calculates (Z = X * Y)
  4. Create a rollup summary field on Opportunity to rollup value of field Z on related opportunityproducts

If the values in product are to be considered at all times i.e. if values changes, then it has needs recalculation for past opportunities

  1. Create fields (viz. X and Y) on opportunity product to persist these values (present in product)
  2. Create trigger on Prodict to detect change field values, to populate these fields (X and Y) on all related opportunityproduct records with modified products
  3. Create a third field Z on Opportunity line item, which calculates (Z = X * Y)
  4. Create a rollup summary field on Opportunity to rollup value of field Z on related opportunityproducts
0

Since Opportunity and opportunity line items are having master detail relationship between them you can go for roll up summary fields. Create RollUp summary field on Opportunity object. Now in options you can choose opportunity line item object as related object and you can choose sum as aggregate function and choose the field on which the summation should happen. I hope this helps you.

  • Yes..I thought of rollup summary fields but the data has to come from products. – sdondeti Sep 30 '14 at 11:58
  • Then triggers are the best option available now. – sunny Sep 30 '14 at 12:02
  • RSF on OpportunityLineItem is the way to go -- you need to use a formula field on OLI that does the calculation and a shadow type=number field in OLI that is sync'ed from the formula field by a Workflow that runs 'every time OLI is edited'. Then use RSF on the shadow field to get sum in Oppo – cropredy Dec 6 '14 at 1:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.