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
SteveDundeeSteveDundee 

How to execute a batch Apex

Hello

 

I have some Batch Apex which I need to execute once, as part of the initialisation of existing Contact records for a new development, but I do not know how to run it. Support have been less than helpful. Can anyone on this board help, please?

 

 

I mean I need to know how best to execute the Apex script that contains this code:

  MailingPreferencesBatchUpdater mpbu = new MailingPreferencesBatchUpdater();
  Database.executeBatch(mpbu);
 

I have consideredputtin gthe code in a Trigger on some object type that we do not currently use (so I would create an instance of that object to trigger the batch), but that feels wrong.

 

I have considered the Apex Scheduler, but I do not have access to that and I do not really know whether it would do the job.

 

It's getting urgent as we go Live with this project at the end of this year.

 

Thanks

 

Steve

 

Best Answer chosen by Admin (Salesforce Developers) 
mtbclimbermtbclimber

You are right to be hesitant/cautious with adding this to a trigger given the limit of concurrent processes and what that would mean to your user's normal operations.

 

Your best bet for now is to create a simple visualforce page with a button that initiates the process.  

All Answers

mtbclimbermtbclimber

You are right to be hesitant/cautious with adding this to a trigger given the limit of concurrent processes and what that would mean to your user's normal operations.

 

Your best bet for now is to create a simple visualforce page with a button that initiates the process.  

This was selected as the best answer
SteveDundeeSteveDundee

Hi Andrew

 

Thanks for that. I've never done a Visualforce page, but that "simple" sounds promising! I'll have a stab at it tomorrow or Monday and see how I get on.

 

Steve

 

XactiumBenXactiumBen
There is a limit on the number of batches you can run at any time so it might be worth creating some functionality that will check to see if a batch is already queued/running before attempting to execute another batch.
SteveDundeeSteveDundee

In general yes it would be sensible to check how many batches are running, but in this case I am running it as a one-off; we have no other batches.

 

 

I wrote a simple Visualforce page with a button to run the batch and it did the trick. 

 

 

Thanks for the help

 

 

Steve

Message Edited by SteveDundee on 12-18-2009 11:41 AM