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
Dee Dee AaronDee Dee Aaron 

Unable to use roll-up summary field to calculate product total.

Hi.
  1. On the Product Object, I have a picklist field: Eligible for Commission (Yes/No).
  2. On the Opportunity Product, I would like to add a field called: Eligible for Commission.
If the product (parent) says eligible for commission “YES”, this value should appear on the opportunity product (child).

I’ve tried using a formula field to map the value and it worked! The problem is that I need to create a roll-up summary field that says: SUM of opportunity products where Eligible for Commission equals “Yes”.
I cannot filter by the Eligible for Commission field because it is a formula field. I also tried creating a workflow rule and a text field. I was able to filter by the text field on the roll-up summary field, but the workflow rule won’t successfully update the child record based on the parent (only the other way around).

I'd prefer to stay away from creating a process builder, if possible. Sometimes, when Salesforce releases updates, the process builders just stop working suddenly. Any advice would be helpful. Thank you!
ShirishaShirisha (Salesforce Developers) 
Hi Dee,

Greetings!

You can achieve this by using the flow invoked by the Process builder and trigger as well.Since you do not want to go with the Process builder then you can proceed with the trigger.

Please find the sample code from the below blogs and make changes according to your business requirement.

https://www.biswajeetsamal.com/blog/custom-rollup-summary-field-using-apex-trigger/

https://medium.com/@palanic/roll-up-summary-from-child-account-to-patent-account-d0d97114e883#:~:text=and%20process%20builder-,Using%20Apex%20Triggers,Named%20as%20Total%20Opportunity%20Amount.

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
gaurav gupta 253gaurav gupta 253
Use After update trigger. Whenever parent field is updated then update all the fields in child object..