[SalesForce] Constructor Syntax in Batch Class

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!

Best Answer

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.

Related Topic