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

Scheduling batch update of select opportunities

Hi, I want to call a nightly batch update process on all of the opportunities in the pipeline (certain criteria).


right now, I am logging in nightly and running a report and clicking all of the opportunities one at a time and clicking "edit" and then "save" and that's ridiculous. how do i automate this?


global class BatchUpdateForecast implements Database.Batchable<sObject>{

   global final String Query;
   global final String Entity;
   global final String Field;
   global final String Value;

   global BatchUpdateForecast (String q, String e, String f, String v){

      Query=q; Entity=e; Field=f;Value=v;

   global Database.QueryLocator start(Database.BatchableContext BC){
      return Database.getQueryLocator(query);

   global void execute(Database.BatchableContext BC, List<sObject> scope){
     //for(sobject s : scope){
     update scope;

   global void finish(Database.BatchableContext BC){


global class batchitupson_schedule implements Schedulable {
global void execute(SchedulableContext scMain) {
BatchUpdateForecast clsBatchItUpSon = new BatchUpdateForecast('Select Id, Name FROM Opportunity','Opportunity','Source_Name__c','Gwins');
ID idBatch = Database.executeBatch(clsBatchItUpSon, 100);


Blobo MoboBlobo Mobo

It looks like you did everything you need to do.  You just need to schedule it up by running this all up in you system log or in execute anonymous:

// Instantiate this schedulable_class all up in here
batchitupson_schedule myDangOleCronJob = new batchitupson_schedule();

//Scheduling like a mofo
System.Schedule('F-in-A Imma scheduled job', '0 0 05 1-31 1-12 ? *', myDangOleCronJob);

The syntax of the job schedule (the second parameter stuck up into the system.schedule method) is same as unix CronJob.


i think by using your batchable and schedulable classes you can automate the process....i am not sure what you are waiting further?

rekha sharmarekha sharma

You can schedule the report, else if you are perfect with the code

go to Setup>develop>apex classes>Schedule Apex(button) , screen will come up to schedule the apex class.