I have a design question that I wanted to run past you guys. I’m not sure what I’m doing is a SF best practice, and could use some feedback.


In my sf, opportunities have a start date and an end date.


On the account, I want to get the # of opportunities that are closed won, and that have an end date greater than today for an account. So when the account is viewed, this will give me the right # at all times. Ok- so I see 2 things- when the opp's 'start date' >= today, the # field needs to increment on the account, then when today > the end date, the account needs to decrement.


Increment: Opportunity - after insert trigger. When the opp is edited, and stage = c/w and start date >= today and end date < today, do a soql and update the # on the account.


On the opp, do a time based workflow. On the opp 'end date,' update a random field on the account. Then on the account run a before update account trigger that does a soql and updates the field.


Is this implementation ok? I don't like the idea that there are a bunch of deferred field updates that are floating around out there. Also, if I’m updating 10 opportunities with the same account, it seems wasteful. Maybe I should create a helper field on the opportunity?

  • Is this purely about what you see on the page, or is this a value you want to report on as well? – Nick Cook Jun 24 '14 at 3:40
  • both. they want to see it on the page and report on them – PartOfTheOhana Jun 24 '14 at 14:12

If you don't need to report on this data you could create a report and summarize/chart the different Opportunities and embed the report chart.

| improve this answer | |
  • This would show the number of oppties on the page, but it wouldn't make it available as a field on the account record. I like the thinking though! – Matt Lacey Jun 23 '14 at 22:46
  • I realize this does not directly answer his question, but the requirement was "So when the account is viewed, this will give me the right # at all times." You can set the report chart to refresh each time a user loads the page, which would ensure the #'s are up to date. My answer might not help this user but it may help someone looking to try and solve a similar problem in the future. – Jenny B Jun 24 '14 at 14:01

I don't like the idea of using code, when it's not necessary.

What I would do is add a Checkbox field on the Opportunity to indicate the Opportunity meets your conditions.

Then I would use Workflow / Field Updates, to update that field on the Opportunity when it matches the criteria

Finally use a Rollup Summary field for the Account to determine how many of the Opportunities meet your requirements.

This should accomplish what you want, and avoid using triggers and code.

| improve this answer | |
  • How can you can do this? The idea of active formula on the opportunity would reference today(). You can't do a RFS on fields that reference a dynamic date – PartOfTheOhana Jun 24 '14 at 14:11
  • @nivyaj The way I read his requirements was that the End Date had to be greater than the day it met the criteria. If this is the case then my solution should work. However if it needs to be greater than the day it is being looked up, then you are correct and my solution won't work. – Minutiae Jun 24 '14 at 14:49

This is the Limitation of Roll Up summary since it will not have the date-based criteria available to it.


So creating a check box or any marker on the Opportunity then bring them up to Account is not feasible since data will be stagnant and formulas/workflows will not auto update those markers unless the record itself is touched.

This is the part where you need to code.

| improve this answer | |

No code necessary! Through the declarative interface you can add a rollup field to the account. Make the field rollup opportunities. You'll have the option in the field settings to rollup only the opportunities that meet a particular criteria, defined by you.

| improve this answer | |
  • 1
    The problem with only using the Rollup Summary is that you can't use Formulas with dates. In OP's case he needs not just the Stage but also his End Date needs to be today. – Minutiae Jun 24 '14 at 1:09

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.