I have a requirement that updates the number of working days in a formula Field based on another date field. I need to keep this field updated everyday and send email alerts based on specific number of business days. I have created the formula field that calculates the number of business days.

How do I keep this formula field updated everyday?

  • 2
    You seem to have a misconception as to how formula fields work. Formula fields are just that, formulas. Salesforce stores the formula itself in their database, and when you (or anyone else, or any thing else) query for the field, the formula is evaluated and a value returned for that point in time. If you wanted to change the definition of a formula field (outside of doing it through Salesforce's web UI), you would need to use the Metadata API. I would not recommend this.
    – Derek F
    Nov 19, 2017 at 14:47
  • To me, this sounds like an XY-problem, where you're asking about how to make the solution (the Y in XY-problem) you've come up with (programatically changing a formula field every day) work instead of asking how to solve the overall problem (the X in the XY-problem). Please give us more details about the problem you're trying to solve, and avoid focusing on a single approach to solving the problem in your question. You can edit your question to include additional details.
    – Derek F
    Nov 19, 2017 at 14:52

1 Answer 1


A possible solution would be to create a Schedulable class, that you would schedule to run at a specific time daily.

When you create your record and you fill in the DateFieldA, FormulaA gets populated automatically with the number of days.

Say, number of days = 5. FormulaA = 5 So, you have to send an email for 5 days.

Create a new field called 'EmailSent'. It would be read only field.

Create a Schedulable class. Query FormulaA and EmailSent.

If (EmailSent < FormulaA) {
    //send email
    //update EmailSent to [value of EmailSent previously queried] + 1
    //so the counter (EmailSent) would be incremented daily until the number of emails required have been sent 
    //meaning number of emails required have already been sent [number of days have already be lapsed]
    //do not do anything here. Else part not needed.

Note #1:

If you are using TODAY()/NOW()/etc in your formula, solution will not work. It will recalculate the number of days [formulaA] everytime the record is updated with new value for EmailSent field.

Then instead of formula field, use TextFieldA or NumberA to keep the number of days.

Update this field via a field update action on a workflow rule.

WF Rule condition would be 'when DateFieldA is changed'.

Note #2:

Also, if you are dealing with bulk data, you may consider using a schedulable batch. Class would be:

public class ClassA implements Database.Batchable<sObject>, Scheduable

Hope it helps.

  • If you need code example, someone posted a question with code snippet where they used implements Database.Batchable<sObject>, Schedulable to send email notification. It may help. Link to question
    – S..
    Nov 19, 2017 at 18:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .