1

I/m facing issue with DML 10001, and i just want to pass the list of more than 10,000 records from trigger to batch apex. Please advise, how to implement batch apex for the list of records to be inserted. I'm directly passing the list to batch apex after processing the logic as below.

if(InsertList.size() > 0){
   Database.executeBatch(new InsertRecords(InsertList));
}

And I just want to pass the records to execute method, as I've nothing to do in the Start(Query) method.

Please Advise.

sanket kumar
  • 15,284
  • 2
  • 24
  • 56
V Reddy
  • 15
  • 1
  • 4

1 Answers1

2

Just return the list in the start method:

public class InsertBatch implements Database.Batchable<sObject> {
  sObject[] source;
  public InsertBatch(sObject[] records) {
    source = records;
  }
  public sObject[] start(Database.BatchableContext context) {
    return source;
  }
  public void execute(Database.BatchableContext context, sObject[] scope) {
    insert scope;
  }
  public void finish(Database.BatchableContext context) {
  }
}
sfdcfox
  • 489,769
  • 21
  • 458
  • 806