1

I have a controller that extends a vfp that calls execute on a batch

 BatchableScorer bs = new BatchableScorer(passedContacts);
 ID batchprocessid = Database.executeBatch(bs);

though when it fires up i can see that job hasn't started in the apex jobs list but when i check the status in the debug console it states that it's "holding". If I then look in the Apex Jobs list, that job is not listed. When i go to execute anonymous window and run the code there, though, it runs as expected (and shows in the Job list). Any ideas?

3
  • What kind of VFP does the class extend? Does it require Admin permissions to use like the Console does? One route is more "direct" than the other. Have you looked in the Flex queue instead of the Apex Batch jobs list?
    – crmprogdev
    Sep 8, 2017 at 11:40
  • the vfp is contact standard controller, <apex:page standardController="Contact" recordSetVar="passedContacts" extensions="BatchProscore"> have checked out the flex queue and nothing there either Sep 8, 2017 at 13:18
  • and i am running and executing all code as the admin user Sep 8, 2017 at 13:45

3 Answers 3

0

I've never tried to start batch classes from visualforce pages, but I'm fairly confident, the controller extension will need to implement the Database.Batchable Interface for you to do that. See Using Batch Apex for more on this.

2
  • Are you sure? if the controller extension implements Database.Batchable, then it has to have start(), execute(), and finish() methods. Class BatchableScorer is the one that should implement Database.Batchable
    – cropredy
    Sep 9, 2017 at 22:19
  • @cropredy. As I stated, I've never done it before. I know his batch class need to impliment Database.Batchable. It seems that his VisualForce controller needs to be doing something else to get the Database.BatchableContext. He might want to consider using the Database.schedulable interface to schedule a 1 time batch job. At a minimum, his extension needs to be public and possibly global. Those are the things that come to mind for me.
    – crmprogdev
    Sep 10, 2017 at 12:44
0

got it. in order to use the standard controller to get the selectedContacts and be able to kickoff the batch match was in my vfp page. I use contact as the standardController, recordsetVar of passedContacts, extending BatchProScoreController and applying the action of generateBatch

Action:

    public void generateBatch(){
        ID batchprocessid = Database.executeBatch(this);
    }

and by calling (this) I was able to keep the checked contacts instead of calling a new instance of the BatchProScoreController. Headache

0

You must be calling batch instance from a method that is called from the constructor of the Visual Force page controller or you must be calling batch instance from the constructor itself. try and call that batch instance from a method that is called on the action of Visual Force page.

Note : you cannot call batch from constructor

2
  • Please do not ask for votes or best answer on SFSE.
    – David Reed
    Oct 21, 2019 at 13:50
  • @DavidReed I just asked so that, others get help from it and they can refer to the correct answer. Oct 21, 2019 at 14:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .