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?

  • 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 '17 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 – useless_duck Sep 8 '17 at 13:18
  • and i am running and executing all code as the admin user – useless_duck Sep 8 '17 at 13:45
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.

  • 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 '17 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 '17 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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.