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
surekha Ksurekha K 

How to write the Batch class and schedule the batch class to run every day

Hi All,

    I want to send email reminders to the opportunity owner and his manager if the opportunity was not changed since 30 days with the condition Opportunity: StageNOT EQUAL TO Order Won AND Opportunity: StatusEQUALSActive.

First email reminder on 30 Days after Last Modified Date.
Second email reminderon 37 Days after Last Modified Date.
Third Email reminder on 44 Days after Last Modified and also 'Status Field' should be updated as a value 'dropped'.

If i go for workflow it will not effect on the existing records it only fire newly creating and edit records.
But i dont want to update the existed records if i update the existed records the last modified date will change so the actual data will change.Is this best approach to go for Batch Class?

If it is correct then how to solve.... I'm not aware on that batch class clearly.
Can any one help me on this please..Actually its little bit urgent also..

Actually i have 112 records with the Last Modified Date before July 8th(on this some records also passed 44 days also) and from 9th July to 9th Aug 603 records was there.And how  to appoach for this and what about for newly creating records?Workflow is not required for newly creating records?Batch apex is taking care of newly creating records also?

This is my scenario...Can anyone help me on this if you have awareness and already faced this issue.

Thanks in Advance.

Regards,
Surekha
Deepak Kumar ShyoranDeepak Kumar Shyoran
You can write a batch class by implements Batchable interface and a schedule class by implement Schedule interface, learn more about Batch with following blogs
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch_interface.htm
http://blog.shivanathd.com/2013/01/how-to-write-batch-class-in.html

You can use the System.schedule method, which takes a cron string to represent the repeating time.
cron expression to run a batch Noon every day
0 0 12 * * ?

Below code will help to schedule a bathc to run every day , just execute this from the system log or anonymous apex section of the IDE onece.
ProcessAccs pa= new ProcessAccs();
String cronStr = '0 0 12 * * ?';
System.schedule('Process Accs Job', cronStr, pa);