You need to sign in to do that
Don't have an account?
Bertrand DB
Multiplication for Roll-Up Summary Field
Hello,
I have a custom object called "Line Item", that has a master-detail relationship on Opportunity.
On an opportunity, I can have multiple "Line items". Each line item has a value.
I would like to multiply these values, and get the result in a field on opportunity.
Example:
"My opportunity":
I have a custom object called "Line Item", that has a master-detail relationship on Opportunity.
On an opportunity, I can have multiple "Line items". Each line item has a value.
I would like to multiply these values, and get the result in a field on opportunity.
Example:
"My opportunity":
- Line item 1: 2
- Line item 2: 10
- Line item 3: 2
Field "my multiplication" on "My opportunity": 2*10*2=40
What I'm trying to achieve is actually a custom field with a field type "Roll up summary", but Salesforce only allows to calcualte Min, Max, Count, Sum...
Any ideas how I can achieve this?
This functionality is not possible with RollUpSummary fields. We need to do this using triggers:
Please mark as best answe.
Regards,
Ramakant
All Answers
Please follow the below code:
Hope this helps.
Please mark Solved if it works.
Mahalo,
Aamir AH Khan
Lead Salesforce Lightning Developer
This functionality is not possible with RollUpSummary fields. We need to do this using triggers:
Please mark as best answe.
Regards,
Ramakant
Thanks,
Sarath
Thank you for your apex suggestions.
I took the one of @Ramakant, as it takes into account deleted lines.
I customized it as it's a little bit different with a custom object, in my case "Line_items__c". In this example, I update Number_of_beneficiaries__c on Opportunity:
Move the below line from Line 22 to Line 24. RollupAmount variable needs to be re-initialized in outer for loop.
You mean before the for loop?
I'm not sure this makes a difference, it still works the same in both case.