Is it possible to run a batchable class from a List<sObject>
that is passed into the constructor as opposed to generating a scope list from a query?
For example, I have a list of singleEmailMessage
object, essentially composed emails ready to be sent like so: Messaging.sendEmail( email_list );
But since there is a limit of 10 emails per transaction and only so many emails within a given transaction, I need this to be batchable.
For now I have something very simple like this started but not sure where to go from here:
global class SendEmailBatch implements Database.Batchable<sObject> {
public String query;
public List<SingleEmailMessage> email_list;
global SendEmailBatch(List<SingleEmailMessage> emails) {
this.query = query;
this.email_list = emails;
}
global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, list<Sobject> scope) {
Messaging.sendEmail( email_list );
}
global void finish(Database.BatchableContext BC) {}
}
As you can see above I'm attempting to just bypass the default parameters but I'm not sure this is the best way, this is my very first batch class. My thought is I need this list in the scope
variable in order for it to properly batch.
Any help you can provide to this question would be very helpful, thanks!
start
method of batch class you will be subject to governor limits..sendEmail
calls, but the size of your list does not have a documented limit as far as I can tell. So just put all yourSingleEmailMessage
instances in one list.