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
SUMAN KUMARI 70SUMAN KUMARI 70 

Batch class to run everyday

Hi All, 
I have a requirement where I need to write a batch class which will run everyday and will send an email to the owner 1 day prior to the closed date at 8 am pacific time.
Kindly please help me by providing the code for this use case.

Thanks a lot in advance.
 
RituSharmaRituSharma
Instead of batch, you may use lightning flow. Refer the URL to know more about flows - https://help.salesforce.com/articleView?id=flow_considerations_trigger_schedule.htm&type=5
SUMAN KUMARI 70SUMAN KUMARI 70
Hi Ritu,
Is this going to work even if the records are not getting edited/created? 
RituSharmaRituSharma
Yes, create Schedule-Triggered flow. 

User-added image
RituSharmaRituSharma
If my answer was helpful, please mark that as the best answer. This would help others in future.
AbhishekAbhishek (Salesforce Developers) 
You need to write an extra class that implements the "Schedulable" interface and calls your batch method. Details of the schedulable interface are here (http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htm)

As an overview you would do:


global class scheduledBatchable implements Schedulable {
   global void execute(SchedulableContext sc) {
      batchContactUpdate b = new batchContactUpdate(); 
      database.executebatch(b);
   }
}


And then run some code like:


scheduledBatch sb = new scheduledBatch();
String sch = '0 0 * * *';
String jobID = system.schedule('Batch COntact Update Job', sch, sb);


For further reference, you can check this too,

https://www.forcetalks.com/blog/how-to-schedule-the-batch-class-at-specific-time/


Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks.