You need to sign in to do that
Don't have an account?
anil 007
how to schedule a batch apex class
hiii,
i have an bach apex class i want to write a schedule class for this batch apx class for evereday afternoon at 1PM
Can anyone provide sample code for schedule apex class
First write a new class which implements the schedulable interface
for example:
global class classname implements schedulable
{
global void execute(SchedulableContext sc)
{
batchclass b = new batchclass(); //ur batch class
database.executebatch(b);
}
}
in the apex class page there is a button called "scheduled Apex" click that from there u can schedule the apex class
try it..................
We use Apex Scheduler to schedule a controller to execute it at a given time in future. For this make an Apex Scheduler Controller and to schedule this controller go to...
Administration Setup->Monitoring->Scheduled Jobs from there we select that Controller class and then provide some time and date to execute it in future.
Below is a sample code of the Apex Scheduler Controller to send an email :
global class ApexScheduledClass Implements Schedulable
{
global void execute(SchedulableContext sc)
{
sendmail();
}
public void sendmail()
{
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
string [] toaddress= New string[]{'vkumar.sri@gmail.com'};
email.setSubject('Testing Apex Scheduler-Subject');
email.setPlainTextBody('Testing Apex Scheduler-Body');
email.setToAddresses(toaddress);
Messaging.sendEmail(New Messaging.SingleEmailMessage[]{email});
}
}
hiii pradeep,
Thanks for reply it workes fine
Hiii....go for this link...
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch_interface.htm
What is the code for debug/execute them and hot to write test class for that.
global String query;
global String subject;
global String body;
global SendReminderEmail(String query, String subject, String body) {
this.query = query;
this.subject = subject;
this.body = body;
}
global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext bc, List<Speaker__c> scope) {
for (Speaker__c speaker : scope) {
EmailManager.sendMail(speaker.Email__c, this.subject, this.body);
}
}
global void finish(Database.BatchableContext bc) {
}
}
Schedule manager on AppExchange - https://appexchange.salesforce.com/listingDetail?listingId=a0N3A00000DqCmYUAV. Can execute your schedule periodically, like you want.
Hope, it will be useful for you!
https://www.sfdc-lightning.com/2018/09/batch-class-in-salesforce.html
You can try the below code And for everyday 1 pm execution, you run it as In case you find any other issue please mention.
If you find your Solution than mark as this as a best answer.
Thanks and Regards
Suraj Tripathi.