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
Pal2011Pal2011 

Send Email Alerts using Batch Apex

Hi,

 

I'm new to the Apex programming.

 

How can I send an Email alerts on particular date of every month using Batch Apex?

 

Thanks!

UVUV

You need to follow these steps:

1-Create a batch apex with your mail functionality.

2-Create a Schedulable class

3- Schedule your schedulable class from the UI or from the apex code.

 

take helps from these links-

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch_interface.htm

http://www.forcelabs.net/2011/10/how-to-use-batch-apex-in-salesforce.html

http://salesforcesource.blogspot.com/2010/02/utilizing-power-of-batch-apex-and-async.html

Pal2011Pal2011

Thanks for the reply,

 

I wrote the code for batch apex. I'm trying to schedule this batch apex to run hourly. Can anybody please help me what am I doing wrong in the code. How can I schedule my Batch Apex Class? Here is my code.

 

global class RScheduler implements Schedulable{

 

global void execute(SchedulableContext SC){

 

// Batch Apex class

BatchApexClass b= new  BatchApexClass();

database.executeBatch(b);

 

RScheduler r= new RScheduler();

String cronStr ='0 0 1 * * * *';

system.schedule('one', cronStr, r);

 

   }

}

TechOwlTechOwl

A portion of the code in your example (below) should not be within the actual "RScheduler" class.

 

RScheduler r= new RScheduler();

String cronStr ='0 0 1 * * * *';

system.schedule('one', cronStr, r);

 

You can use "Execute Anonymous" in Eclipse (for example) to execute the code above & the job will be scheduled hourly.

 

Also, the other two lines can be combined into one line of code: Database.ExecuteBatch(new BatchApexClass());

 

Hope this helps!