You need to sign in to do that
Don't have an account?
sp13
how to schedule apex class yearly
how can i schedule this code yearly?
i want it to run every January 1 at 12am
when i go to Apex Classes > Schedule Apex, the only choices are weekly and monthly
what if i only want it to run yearly?
i want it to run every January 1 at 12am
global class autoCreateIS implements Schedulable {
global void execute(SchedulableContext arc) {
Date dateToday = system.Today();
Integer year = dateToday.year();
Integer nextYear = (year + 1);
IS__c createIS = new IS__c();
createIS.Name = String.valueOf(nextYear);
insert createIS;
}
}
global void execute(SchedulableContext arc) {
Date dateToday = system.Today();
Integer year = dateToday.year();
Integer nextYear = (year + 1);
IS__c createIS = new IS__c();
createIS.Name = String.valueOf(nextYear);
insert createIS;
}
}
when i go to Apex Classes > Schedule Apex, the only choices are weekly and monthly
what if i only want it to run yearly?
The way you were is wrong, the code which i have sent ,please paste in developer console and execute and see the status in Administration Setup-->Monitoring-->Scheduled Jobs it will be showing up as required.
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Srinivas
SFDC Certified Developer
All Answers
As per your requirement i am sending code to schedule the class at 12 Am at every January 1.
autoCreateIS schedule =new autoCreateIS();
String sch ='0 0 0 1 1 ?';
System.schedule('YOurchoiceofname Scheduled',sch, schedule);
if you get any kind of issue in this ping reply me.
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Srinivas
SFDC Certified Developer
tnx @Sri549!
should i still go to Apex Classes > Schedule Apex to create new schedule for this?
i added your code in my code but used a different time and date(February 17, 7:40PM) to test if it's working:
global class autoCreateIS implements Schedulable {
global void execute(SchedulableContext arc) {
autoCreateIS schedule =new autoCreateIS();
String sch = '0 40 19 17 2 ?';
System.schedule('autoCreateISsched',sch, schedule);
Date dateToday = system.Today();
Integer year = dateToday.year();
Integer nextYear = (year + 1);
IS__c createIS = new IS__c();
createIS.Name = String.valueOf(nextYear);
insert createIS;
}
}
but it didnt work :(
The way you were is wrong, the code which i have sent ,please paste in developer console and execute and see the status in Administration Setup-->Monitoring-->Scheduled Jobs it will be showing up as required.
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Srinivas
SFDC Certified Developer
I was executing the script,, It got queued, still not running the job. Is it some salesforce default issue.?
Thanks
Namina