• Bhaskar Arora
  • NEWBIE
  • 0 Points
  • Member since 2012
  • Developer

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 5
    Replies

If you want to run a scheduler every 5 Minutes.

 

Note:Every thing has to be done in scheduler class.

 

1.you have to run a scheduler for the first time so do it on action of click of a button or from Developer console
say for example at 10 am.

 

2.In scheduler class use gettrigger id.

 

3.When scheduled job runs you will get the scheduler job id in scheduler class.

 

4.so write a query on Cron trigger where you will get cron Expression related to the scheduled job id when class is called.

 

5.extract the mintes from the cron expression using string functions.

 

6.now schedule a job with current hour and adding five minutes in cron expression minutes u get.

 

7.
if(Minutes==55 )
{
minute=0;

}
else
{
minute=minute+5;
}


Code is like this...

string cronid;
cronid=sc.getTriggerId();

CronTrigger scheduledjob=new CronTrigger(Id=cronid);
string value=[Select CronExpression From CronTrigger where id=:cronid limit 1].CronExpression;
List <string> value1 =value.split(' ');

system.abortJob(scheduledjob.Id); //abort scheduled job

Datetime sysTime = System.now();
integer minute=integer.valueof(value1[1]);
integer hour1=sysTime.hour();
if(integer.valueOf(value1[1])==55)
{
minute=0;
}
else
{
minute=minute+5;
}

String chron_exp = '' + sysTime.second() + ' ' + minute + ' 0-23 * * ?';
SchedulerMassEmail scheduler = new SchedulerMassEmail();
string id=System.schedule('MassEmail Scheduler',chron_exp,scheduler);

 

So the schedule job will be made with the same name every time.

 

There is one more way of doing it.

schedule job say for

 

 string sch22='0 0 * * * ?';     

string sch22='0 5 * * * ?';

string sch22='0 10 * * * ?';

string sch22='0 15 * * * ?';

string sch22='0 20 * * * ?';

string sch22='0 25 * * * ?';

string sch22='0 30 * * * ?';

string sch22='0 35 * * * ?';

string sch22='0 40 * * * ?';

string sch22='0 45 * * * ?';

string sch22='0 50 * * * ?';

string sch22='0 55 * * * ?';

so sy these 12 jobs will run once in an hour,

 

so sy at 10 then 10.05 and the 10.10 like this . :):)

If you want to run a scheduler every 5 Minutes.

 

Note:Every thing has to be done in scheduler class.

 

1.you have to run a scheduler for the first time so do it on action of click of a button or from Developer console
say for example at 10 am.

 

2.In scheduler class use gettrigger id.

 

3.When scheduled job runs you will get the scheduler job id in scheduler class.

 

4.so write a query on Cron trigger where you will get cron Expression related to the scheduled job id when class is called.

 

5.extract the mintes from the cron expression using string functions.

 

6.now schedule a job with current hour and adding five minutes in cron expression minutes u get.

 

7.
if(Minutes==55 )
{
minute=0;

}
else
{
minute=minute+5;
}


Code is like this...

string cronid;
cronid=sc.getTriggerId();

CronTrigger scheduledjob=new CronTrigger(Id=cronid);
string value=[Select CronExpression From CronTrigger where id=:cronid limit 1].CronExpression;
List <string> value1 =value.split(' ');

system.abortJob(scheduledjob.Id); //abort scheduled job

Datetime sysTime = System.now();
integer minute=integer.valueof(value1[1]);
integer hour1=sysTime.hour();
if(integer.valueOf(value1[1])==55)
{
minute=0;
}
else
{
minute=minute+5;
}

String chron_exp = '' + sysTime.second() + ' ' + minute + ' 0-23 * * ?';
SchedulerMassEmail scheduler = new SchedulerMassEmail();
string id=System.schedule('MassEmail Scheduler',chron_exp,scheduler);

 

So the schedule job will be made with the same name every time.

 

There is one more way of doing it.

schedule job say for

 

 string sch22='0 0 * * * ?';     

string sch22='0 5 * * * ?';

string sch22='0 10 * * * ?';

string sch22='0 15 * * * ?';

string sch22='0 20 * * * ?';

string sch22='0 25 * * * ?';

string sch22='0 30 * * * ?';

string sch22='0 35 * * * ?';

string sch22='0 40 * * * ?';

string sch22='0 45 * * * ?';

string sch22='0 50 * * * ?';

string sch22='0 55 * * * ?';

so sy these 12 jobs will run once in an hour,

 

so sy at 10 then 10.05 and the 10.10 like this . :):)

Hi all,

 

I want to ask how to handle ENTER event key press in visual force page? Is it possible using javascript or any suggestions? My case is I have 2 buttons in visualforce page and if I click ENTER regardless where I hit ENTER, I want my button no.2 to be run.. Is that possible?

Any suggestions would be great..

 

Thanks

Is it something like this?

 

// every 5 minutes
String sch = '0 5 * * * ? ';