function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Peter FranzenPeter Franzen 

How do I reset a counter field on the 1st of each month?

I need to be able to have a field on a user's profile that is incremented according to some rules (it counts the number of cases that meet a certain criteria) and then resets that number to zero on the 1st of each month.

The field will be used to calculate commissions for the user.  Basically, if the field equals 0-5 then a commission is generated, and if it is 6+ then a larger commission is generated.

I'm not quite sure where to start on doing this.
Hargobind_SinghHargobind_Singh
Hi Peter, I could see a few options: 
  • You could write some apex code to reset the value in the counter field and schedule the code to run on every 1st automatically. Here is some information, but requires programming
  • You could have a formula field that can calculate the number of days from 1st day of current month and use this field to feed your business logic rather than relying on value-fields. This would require modifiying your logic of how you are using the values.

I know this is vague, but depending on what option you would want to take, someone could help you with further details ?
Peter FranzenPeter Franzen
The first option would be best, but I have no idea where to start when it comes to writing Apex code to do that.  It would need to reset the counter on every user's profile on the 1st of each month.