Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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.

Set-up:

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

Problem:

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.

Implementation:

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.

Decrement:

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.

Question:

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?

share|improve this question
    
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 at 3:40
    
both. they want to see it on the page and report on them –  nivyaj Jun 24 at 14:12

4 Answers 4

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.

share|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 –  nivyaj Jun 24 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 at 14:49

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

https://success.salesforce.com/ideaView?id=08730000000BrUAAA0

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.

share|improve this answer

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.

share|improve this answer
    
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. –  mast0r Jun 23 at 20:06
    
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! –  LaceySnr Jun 23 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. –  jjbennett530 Jun 24 at 14:01

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.

share|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 at 1:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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