0

I'm new to the development side with no real development background in any language. So I wrote this batch class, and I can't quite figure out how to implement the proper syntax for the constructor. This is what the constructor requires:

MD_PersonatorBatch(String q, Boolean updateContact, Boolean processAll)

This is what i've got so far:

global class listwareWeekly implements Database.Batchable<sObject>
    {

        global Database.QueryLocator start(Database.BatchableContext BC)
        {
            String query = ('SELECT Id, MailingCountry, Email, Melissa_Email_Result_Codes__c FROM Contact WHERE isDeleted = False LIMIT 100');
            return Database.getQueryLocator((query)true, false); //I know this is wrong. I've tried a few different things, but this is where i'm at.
        }                                                          

        global void execute(Database.BatchableContext BC, List<Contact> scope)
        {
                MDPERSONATOR.MD_PersonatorBatch bb = new MDPERSONATOR.MD_PersonatorBatch();
                Database.executeBatch(bb);
        } 
        global void finish(Database.BatchableContext BC)
        {
        }
    }

Any assistance would be greatly appreciated!

4
  • What is your batch actually trying to do? Right now, the implementation seems a little off-kilter; the execute() method doesn't do anything with its scope. Have you worked through the Batch Apex module on Trailhead?
    – David Reed
    Sep 17, 2019 at 16:05
  • I'm trying to send records to a class in a managed package to validate email addresses. I have been through the trailhead, but it didn't answer a number of questions I had so I've spent a great deal of time googling.
    – Sean AB
    Sep 17, 2019 at 16:29
  • I'm doing a batch class so I can schedule runs throughout the week. I was informed by their support to limit the batch size to 100 records. They're a bit shy on documentation for this. Thanks for your input David, but I really just need to know how to form the arguments for the constructor.
    – Sean AB
    Sep 17, 2019 at 17:11
  • That was another route I couldn't figure out so I wrote a schedulable class to run this class. If it'll work that way then that's a perfect answer.
    – Sean AB
    Sep 17, 2019 at 17:16

1 Answer 1

3

Based on what you've got here:

MD_PersonatorBatch(String q, Boolean updateContact, Boolean processAll)

and

MDPERSONATOR.MD_PersonatorBatch bb = new MDPERSONATOR.MD_PersonatorBatch();

it sounds like you're not really trying to write a batch class; you're trying to call a batch class that is supplied by a managed package.

If that is the case, you don't need to write this code at all. For a one-time invocation of the batch, you'll just need to run Anonymous Apex from your Developer Console:

Database.executeBatch(
    new MDPERSONATOR.MD_PersonatorBatch(
        'SELECT Id, MailingCountry, Email, Melissa_Email_Result_Codes__c FROM Contact WHERE isDeleted = False LIMIT 100',
        true,
        false
    ),
    100
);

With a batch class, you generally won't need the LIMIT 100 clause - batch classes are designed to process thousands of records in batches. However, you'll really just need to consult the documentation for your managed package for any unique limitations of this functionality.

Edit: based on your comment

I'm doing a batch class so I can schedule runs throughout the week. I was informed by their support to limit the batch size to 100 records. They're a bit shy on documentation for this. [...]

You don't need to write a batch class; you need to write a Schedulable class, whose execute() message does something like what I show above. The Schedulable interface allows you to schedule regular runs.

A LIMIT clause on a SOQL query does not affect the batch size; it controls the total number of records retrieved. The batch size is controlled by the second argument to Database.executeBatch(), which I've updated above.

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.