I have an "employee" object that has staff information including leave balance which is a formula that has an accrual rate and subtracts from a child object "leave requests" roll-up sum.

The use case is that every year, on Jan 1, if an employee has accrued more than 10 days then in the new year the leave balance has to refresh to ten days. E.g. if I have 14 days in December 31, then on January 1, this needs to automatically deduct to 10 days.

How can a formula field be updated on a specific date, continuously? NO CODE preferable, but if you have an Apex solution, please consider that I am a novice in your explanation.

  • 2
    The only kind of workflow that would fire without a field update on a particular date would be time-based workflow. That having been said, this would best be suited to scheduled batch job. As you're new to apex, I won't try to explain it to you. For more on it, I'd recommend you go through the Trailhead Modules for Asynchronous Apex after you go through the basic ones.
    – crmprogdev
    Nov 27, 2016 at 18:14
  • Is the deduction example in the question correct? You mention bringing the leave balance back to 10 days, but then subtract 10 days from the balance of 14. Did you mean to subtract 4 days? Nov 27, 2016 at 20:58
  • Yes, to subtract 4 days. Nov 28, 2016 at 8:25

1 Answer 1


I suspect the formula isn't the correct place to perform such an operation.

An alternative approach would be to create addition "leave request" records as required to reset the leave balance at the required time.


  • Reach Jan 1st, Schedule starts a batch job
  • Batch job is run over a SOQL query for all employee records where the leave balance formula indicates a balance greater than 10 days
  • In the batch execution, create a collection of adjustment leave request records that will reset the balance for each employee in that batch back to 10.
  • Insert adjustment leave records.

This will require Apex code for the batch job and corresponding test cases. IMHO that would be beneficial in this case to have a good set of test cases. I.e. Check for employees with balances below, at, and above the 10 day threshold.

You might need to create an additional field, or even an entirely new custom object, to represent the leave adjustments.

Another advantage of this approach is that you can see and report on exactly what adjustments were made and when. Noting what the formula balance was when the adjustment would be useful.

You must log in to answer this question.

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