I have created 4 custom fields on account, and I want those fields to store the number of opportunities according to their status(e.g. Active, Inactive, Open, Lost). Once the admin creates an Open Opportunity on an Account, the number of Open Opportunities [which is a custom field on Account] should increase. I've tried using Process Builder, Apex classes/triggers and Workflow rules all in futility.
1 Answer
You can use simple roll-up summary fields. Go to the Customize Accounts Fields area in Setup, and create four new roll-up summary fields, one for each status. If you'd like to do this with Apex Code, you should search other questions on this forum that include answers from several sources on how to build a custom roll-up relationship trigger, or consider using the Declarative Roll-Up Summary tool that's already been built.
-
I thought Roll-up summary field values cannot be changed. Apparently, that's false. @sfdcfox– OladipoCommented Mar 12, 2016 at 18:33
-
@DIPXOID They can't be changed by users (cannot be edited), but will always show correct values, which is presumably the purpose of creating those fields.– sfdcfox ♦Commented Mar 12, 2016 at 18:34
-
Alright. I will check it out and rate the answer as appropriate.– OladipoCommented Mar 12, 2016 at 18:39
-
The issue with this I've been struggling with is that the easiest way is to create new roll-up summary fields. But I can't use TODAY (I mean today's date) as a condition in it; and I need it. The other options to use are not as straightforward.– OladipoCommented Mar 16, 2016 at 9:39