function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
John NeilanJohn Neilan 

Scheduled Apex

Hello,

I've created a trigger to count Tasks related to an Opportunity.  The trigger fires when a Task is inserted, updated, or deleted and works as expected. I would like to schedule a nightly update that on Tasks with a certain Subject that will refresh the counts on the Opportunity  I created the class below from SFDC documentation, but I'm unclear on how to include the scheduled run time and how to implement it.  Can anyone help!
 
global class RenewalTasksDaily implements Schedulable {
   global void execute(SchedulableContext ctx) {
      CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime
                		FROM CronTrigger
                		WHERE Id = :ctx.getTriggerId()];

      System.debug(ct.CronExpression);
      System.debug(ct.TimesTriggered);

      ClassRenewalTaskCount TC = new ClassRenewalTaskCount();
      TC.taskCount(Trigger.new);
   }
}

 
Best Answer chosen by John Neilan
Jerome LusinchiJerome Lusinchi
Hi John,

To schedule a schedulable class, you can go in the Setup > Develop > Apex Class
Then you'll have the "Schedule Apex" Button.
You'll then be able to choose the class and frequency.

Regards,
Jerome

All Answers

Jerome LusinchiJerome Lusinchi
Hi John,

To schedule a schedulable class, you can go in the Setup > Develop > Apex Class
Then you'll have the "Schedule Apex" Button.
You'll then be able to choose the class and frequency.

Regards,
Jerome
This was selected as the best answer
John NeilanJohn Neilan
Thanks!  Any idea how to schedule more frequently than once per day?
Jerome LusinchiJerome Lusinchi
HI John,
if the schedule apex interface is not enought for your needs, you can always schedule it in the developer console.
you can then schedule it more frequently

Regards,
Jerome