You need to sign in to do that
Don't have an account?
VSK98
Could any body tell how write schedule class
Hi all,
I need to run the schedule class for every day @ 1 PM ...........
Here is the my batch class
global class sendwagenoticestoemployees Implements Database.Batchable <sObject> {
global Database.queryLocator start(Database.BatchableContext bc) {
String SOQL = 'SELECT Id, WTPAA_Employee_Email__c,WTPAA_Related_To__c,WTPAA_Living_Wage__c FROM WTPAA_Wage_Notice__c WHERE WTPAA_Living_Wage__c = false ';
return Database.getQueryLocator(SOQL);
}
global void execute(Database.BatchableContext bc, List<WTPAA_Wage_Notice__c> wagenotice) {
List<Messaging.SingleEmailMessage> mailList = new List<Messaging.SingleEmailMessage>();
Emailtemplate et = [select id, developername , IsActive from Emailtemplate where developername = 'WTC_Offer_is_Ready_for_Review' AND IsActive = true];
for(WTPAA_Wage_Notice__c w: wagenotice) {
List<String> toAddresses = new List<String>{w.WTPAA_Employee_Email__c};
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(toAddresses);
mail.SetTemplateid(et.id);
mail.setSaveAsActivity(false);
mail.setTargetObjectId(w.WTPAA_Related_To__r.id);
system.debug('ID of Contact' +w.WTPAA_Related_To__r.id);
system.debug('IDDDDDDDDDDD*******' +et.id);
mailList.add(mail);
system.debug('size of the list' +mailList.size() );
}
Messaging.sendEmail(mailList);
}
global void finish(Database.BatchableContext bc) {
}
}
please help me out.
I need to run the schedule class for every day @ 1 PM ...........
Here is the my batch class
global class sendwagenoticestoemployees Implements Database.Batchable <sObject> {
global Database.queryLocator start(Database.BatchableContext bc) {
String SOQL = 'SELECT Id, WTPAA_Employee_Email__c,WTPAA_Related_To__c,WTPAA_Living_Wage__c FROM WTPAA_Wage_Notice__c WHERE WTPAA_Living_Wage__c = false ';
return Database.getQueryLocator(SOQL);
}
global void execute(Database.BatchableContext bc, List<WTPAA_Wage_Notice__c> wagenotice) {
List<Messaging.SingleEmailMessage> mailList = new List<Messaging.SingleEmailMessage>();
Emailtemplate et = [select id, developername , IsActive from Emailtemplate where developername = 'WTC_Offer_is_Ready_for_Review' AND IsActive = true];
for(WTPAA_Wage_Notice__c w: wagenotice) {
List<String> toAddresses = new List<String>{w.WTPAA_Employee_Email__c};
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(toAddresses);
mail.SetTemplateid(et.id);
mail.setSaveAsActivity(false);
mail.setTargetObjectId(w.WTPAA_Related_To__r.id);
system.debug('ID of Contact' +w.WTPAA_Related_To__r.id);
system.debug('IDDDDDDDDDDD*******' +et.id);
mailList.add(mail);
system.debug('size of the list' +mailList.size() );
}
Messaging.sendEmail(mailList);
}
global void finish(Database.BatchableContext bc) {
}
}
please help me out.
Here is the schedule class for your batch class. You can even execute your batch class in exceute anonymous window from developer console too.
i have some doubts????????
can i use batch is 200;
I need to run the schedule class for every day @ 1 PM ..........
i have checked ur code there is no cron expression????????.
Shall i change the batch size.......??????
If i give morethan 200 what will happen to my schedule class? could u explain it ????
global class sendwagenoticestoemployeesSchedule implements Schedulable {
global void execute(SchedulableContext sc) {
//Define your batch size.
integer BATCH_SIZE = 100;
sendwagenoticestoemployees pwnBatch = new sendwagenoticestoemployees ();
system.debug('**** sendwagenoticestoemployeesSchedule : starting batch exection*****************');
Id batchId = database.executeBatch(pwnBatch , BATCH_SIZE);
system.debug('**** sendwagenoticestoemployeesSchedule : Batch executed batchId: '+batchId);
}
}
You can have batch size less or equals to 200. salesforce chunks the records returned by the Database.QueryLocator into batches of 200.
I can see you are using your batch to send emails. There is a limit to send number of emails from salesforce.The daily limit for emails sent through email alerts is 1,000 per standard Salesforce license per organization—except for free Developer Edition and trial organizations, where the daily workflow email limit is 15 per standard Salesforce license. The overall organization limit is 2,000,000. This limit applies to emails sent through email alerts in workflow rules, approval processes, flows, processes, or the REST API.
Cron expression job to run everyday at 1 PM is following. use this to schedule your apex class in exceute anonymous window from developer console.
Then you can have the crontab definition in that as well making it easier to start it from the "Execute anonymous window".
Good luck!