A blog containing Salesforce coding examples in detail.It's a place where you can find solutions to the problems that you may face in your daily salesforce coding. Apex classes,visual force page,we services,Integration,plugins,extensions,Lightning web components,Aura components,Email Messages,Sales cloud,service Cloud,Marketing Cloud.Lightning Web components,salesforce.com, Salesforce Tips and Tricks,short cuts,ApexMocks,Stubs, visibility,Salesforce Shorts
Tuesday, December 31, 2019
Monday, December 2, 2019
Trigger must be associated with a job detail error while scheduling the batch job
Trigger must be associated with a job detail error while scheduling the batch job
Problem: This error occurred while scheduling the batch job using cron expression.
System.schedule('Schedule Batch Job that runs only once after 5 mins ', '0 '+sMinute+' '+sHour+' '+sDayOfMonth+' '+sMonth+' ?'+' '+sYear, new AccountUpdatorBatchSchedular());
Solution: Notice in the above sample code, there is space after the name of the job i.e Schedule Batch Job that runs only once after 5 mins.
When I remove extra spaces,I was able to resolve the issue.
System.schedule('Schedule Batch Job that runs only once after 5 mins', '0 '+sMinute+' '+sHour+' '+sDayOfMonth+' '+sMonth+' ?'+' '+sYear, new AccountUpdatorBatchSchedular());
Problem: This error occurred while scheduling the batch job using cron expression.
System.schedule('Schedule Batch Job that runs only once after 5 mins ', '0 '+sMinute+' '+sHour+' '+sDayOfMonth+' '+sMonth+' ?'+' '+sYear, new AccountUpdatorBatchSchedular());
Solution: Notice in the above sample code, there is space after the name of the job i.e Schedule Batch Job that runs only once after 5 mins.
When I remove extra spaces,I was able to resolve the issue.
System.schedule('Schedule Batch Job that runs only once after 5 mins', '0 '+sMinute+' '+sHour+' '+sDayOfMonth+' '+sMonth+' ?'+' '+sYear, new AccountUpdatorBatchSchedular());
How to schedule a batch job to run only once after 5 mins
How to schedule a batch job to run only once after 5 mins
Assume AccountUpdatorBatchSchedular is the schedular class that schedules the batch job.
global class AccountUpdatorBatchSchedular implements schedulable {
global void execute(SchedulableContext sc) {
AccountUpdatorBatch b = new AccountUpdatorBatch();
database.executebatch(b);
}
}
AccountUpdatorBatch is the actual batch job.
Sample Code to schedule job:
// Add 5 minutes to current Time
DateTime dtCurrentTime = System.now().addminutes(5);
String sHour = '', sMinute='', sDayOfMonth='', sMonth='', sYear='';
sMinute = String.ValueOf(dtCurrentTime.minute());
sHour = String.ValueOf(dtCurrentTime.hour());
sDayOfMonth = String.ValueOf(dtCurrentTime.day());
sMonth = String.ValueOf(dtCurrentTime.month());
sYear = String.ValueOf(dtCurrentTime.year());
System.schedule('Schedule Batch Job that runs only once after 5 mins', '0 '+sMinute+' '+sHour+' '+sDayOfMonth+' '+sMonth+' ?'+' '+sYear, new AccountUpdatorBatchSchedular());
Output:
Assume AccountUpdatorBatchSchedular is the schedular class that schedules the batch job.
global class AccountUpdatorBatchSchedular implements schedulable {
global void execute(SchedulableContext sc) {
AccountUpdatorBatch b = new AccountUpdatorBatch();
database.executebatch(b);
}
}
AccountUpdatorBatch is the actual batch job.
Sample Code to schedule job:
// Add 5 minutes to current Time
DateTime dtCurrentTime = System.now().addminutes(5);
String sHour = '', sMinute='', sDayOfMonth='', sMonth='', sYear='';
sMinute = String.ValueOf(dtCurrentTime.minute());
sHour = String.ValueOf(dtCurrentTime.hour());
sDayOfMonth = String.ValueOf(dtCurrentTime.day());
sMonth = String.ValueOf(dtCurrentTime.month());
sYear = String.ValueOf(dtCurrentTime.year());
System.schedule('Schedule Batch Job that runs only once after 5 mins', '0 '+sMinute+' '+sHour+' '+sDayOfMonth+' '+sMonth+' ?'+' '+sYear, new AccountUpdatorBatchSchedular());
Output:
Subscribe to:
Posts (Atom)
-
How to retrieve validation rules using package.xml in vs code salesforce - Salesforce Globe For You Problem : Assume a validation Mobile_...
-
Assume AccountPage is an apex class in salesforce. Sample Xml file : <?xml version="1.0" encoding="UTF-8"?> &l...