You need to sign in to do that
Don't have an account?
Nitin Sharma
Created a schedulable class for batch job but its not working.
Batch class
Anyone can solve this issue.
Thanks
Nitin Sharma
global class BirthdayNotificationBatch Implements Database.Batchable <sObject> { global Database.queryLocator start(Database.BatchableContext bc) { Date tody = system.today(); String SOQL = 'SELECT Id, Name, Email__c FROM Contact WHERE DAY_IN_MONTH(Birthdate) = ' + tody.day() + ' AND CALENDAR_MONTH(Birthdate) = ' + tody.month(); return Database.getQueryLocator(SOQL); } global void execute(Database.BatchableContext bc, List<Contact> listContacts) { List<Messaging.SingleEmailMessage> mailList = new List<Messaging.SingleEmailMessage>(); for(Contact c : listContacts) { List<String> toAddresses = new List<String>{c.Email}; Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setToAddresses(toAddresses); mail.setSubject('Happy Birthday'); String messageBody = '<html><body>Hi ' + c.Name + ',<br/>Happy Birthday.<br/>Many More Happy '+ 'Returns of the day.<br/><br/><b>Regards,</b><br/>Admin</body></html>'; mail.setHtmlBody(messageBody); mailList.add(mail); } Messaging.sendEmail(mailList); } global void finish(Database.BatchableContext bc) { } }Schedule class
global class ScheduleBatch Implements Schedulable { global void execute(SchedulableContext sc){ BirthdayNotificationBatch sb = new BirthdayNotificationBatch(); Database.executeBatch(sb); } ScheduleBatch my = new ScheduleBatch(); String str = '0 30 11 * 5 ?'; System.schedule('sb', str, my); }But its not working.
Anyone can solve this issue.
Thanks
Nitin Sharma
1) http://amitsalesforce.blogspot.in/2016/02/batch-apex-in-salesforce-test-class-for.html
How to Schedule scheduler class
There are two option we have schedule the scheduler classes.
1) By System Scheduler.
2) By Developer console
System Scheduler.
Step 1) Click on Setup->Apex class. Then search Schedule Apex button.
Step 2) Select the scheduler class and set Time like below screen shot.
By Developer console
Execute below code from developer console :-
ScheduleBatch m = new ScheduleBatch ();
String sch = '20 30 8 10 2 ?';
String jobID = system.schedule('Merge Job', sch, m);
1) http://www.simplysfdc.com/2015/02/salesforce-send-birthday-email.html
Sample code for you
Please check below post for "Creating an Automatic Birthday Email"
1) https://help.salesforce.com/HTViewSolution?id=000181218&language=en_US
....................................
In your case please update your Batch job like below (i found you was using the email__c field not email field)
Scheduler class like below You can excute your batch job from developer console also with below code.
BirthdayNotificationBatch sb = new BirthdayNotificationBatch();
Database.executeBatch(sb);
Let us know if this will help you
Thanks
Amit Chaudhary
All Answers
1) http://amitsalesforce.blogspot.in/2016/02/batch-apex-in-salesforce-test-class-for.html
How to Schedule scheduler class
There are two option we have schedule the scheduler classes.
1) By System Scheduler.
2) By Developer console
System Scheduler.
Step 1) Click on Setup->Apex class. Then search Schedule Apex button.
Step 2) Select the scheduler class and set Time like below screen shot.
By Developer console
Execute below code from developer console :-
ScheduleBatch m = new ScheduleBatch ();
String sch = '20 30 8 10 2 ?';
String jobID = system.schedule('Merge Job', sch, m);
1) http://www.simplysfdc.com/2015/02/salesforce-send-birthday-email.html
Sample code for you
Please check below post for "Creating an Automatic Birthday Email"
1) https://help.salesforce.com/HTViewSolution?id=000181218&language=en_US
....................................
In your case please update your Batch job like below (i found you was using the email__c field not email field)
Scheduler class like below You can excute your batch job from developer console also with below code.
BirthdayNotificationBatch sb = new BirthdayNotificationBatch();
Database.executeBatch(sb);
Let us know if this will help you
Thanks
Amit Chaudhary
Its working I used wrong field name.