You need to sign in to do that
Don't have an account?
TheRealist
How to Schedule a batch Apex using system.schdule ?
How to Schedule a batch Apex using system.schdule with code not through UI and where to write it ,
Below is my sample code:
public class BatchLeadDelete implements database.Batchable<sobject>
{
list<lead> llist=new list<lead>();
public string query='select id,name,Phone from lead';
public string flag='12345';
public database.querylocator start(database.BatchableContext bc){
return database.getQueryLocator(query);
}
public void execute(database.BatchableContext bc,list<lead> le){
for(lead l:le){
if(l.Phone==flag)
{
llist.add(l);
}
}
delete llist;
}
public void finish(database.BatchableContext bc){
}
}
I called the above class with below code
BatchLeadDelete l=new BatchLeadDelete();
database.executeBatch(l,50);
Below is my sample code:
public class BatchLeadDelete implements database.Batchable<sobject>
{
list<lead> llist=new list<lead>();
public string query='select id,name,Phone from lead';
public string flag='12345';
public database.querylocator start(database.BatchableContext bc){
return database.getQueryLocator(query);
}
public void execute(database.BatchableContext bc,list<lead> le){
for(lead l:le){
if(l.Phone==flag)
{
llist.add(l);
}
}
delete llist;
}
public void finish(database.BatchableContext bc){
}
}
I called the above class with below code
BatchLeadDelete l=new BatchLeadDelete();
database.executeBatch(l,50);
Please try below schedulable class
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_scheduler.htm
Please let us know if this will help you
Hi there,
If you already have a schedular class written then you could either schedule it to run from the UI or you could run it via developer console.
To run it from dev console:
System.schedule('Schedule_Job_Name', '0 15 * * * ?', new schedulableClass());
This will schedule the job every 15th minute of each hour.
Let me know how often you want to schedule your schedular class.
Thanks!
Hi justin_sfdc, how to schedule the job to run on
Mondays of every week at 10 hr 15th min
Please follow below Steps:-
Step1 :- Create schduler class like below :-
Step 2 :- go to classes
Setup->Apex classes then click on Schedule Apex button
Step 3:- Then add date and time like below and select your scheduler class in Apex class Name
Please mark this as solution if this will help you
Hi there,
Try this:
System.schedule('Scheduled Job 1', '0 15 22 ? * MON', new ScheduledClass());
Once you execute it, you can go to the Scheduled jobs to verify what time the time has been scheduled to run for.
Hope this works! Let me know if it does not then I can try to run in my machine.
Thanks!