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
Dan LillyDan Lilly 

Help with Apex Code to Update Counter Field to 0 Daily

I am new to APEX, but keep seeing 50 different ways to achieve this, so hoping I can get some Guidance. 

On my lead and opportunity objects I have a custom field called "Dialer Daily". Every time a call is made I am using a workflow to increase that counter field. Every day I need to reset the field "Dialer Daily" to 0 every day. There are no other restrictions or requirements, just need to set that field to 0 on ALL Lead and Opportunity objects. I appreciate the help in Advance!
ShirishaShirisha (Salesforce Developers) 
Hi Dan,

Greetings!

You need to create the batch class which should schedule for everyday at particular time to update all the Lead records as mentioned here (https://trailblazers.salesforce.com/answers?id=90630000000hcm3AAA).

Please mark it as best answer if it helps you to fix the issue.

Thank you!

Regards,
Shirisha Pathuri
Andrew GAndrew G
Silly question 
Could you use a scheduled trigger flow?
User-added image
Schedule for Daily at 5am
Filter by Daily Dialer field > 0
for each record, set the field to 0

Untested and not thought through, but could work.  Only thought would be how does  it handle bulk numbers?

regards
Andrew