You need to sign in to do that
Don't have an account?
too many dml rows error when using implementing database.stateful
I have a batch class that implements database.stateful so global values are visible across batches. I then save the data in the finish method.
All worked fine until there was enough data involved that the save is now generating a Too Many DML rows error.
I could use some guidance about a pattern to use to get around this issue as changing the batch size won't matter since the save needs to be in the finish method.
I realize this is a simplistic approach, but could I do something as basic as breaking the list to be saved into multiple lists then inserting them with separate commands but within the same context?
All worked fine until there was enough data involved that the save is now generating a Too Many DML rows error.
I could use some guidance about a pattern to use to get around this issue as changing the batch size won't matter since the save needs to be in the finish method.
I realize this is a simplistic approach, but could I do something as basic as breaking the list to be saved into multiple lists then inserting them with separate commands but within the same context?
global class batchClass implements Database.Batchable<sObject>, database.stateful { global map<id, sobject> dataStruct; global string q = 'select whatever from sObject'; global Database.QueryLocator start(Database.BatchableContext BC) { dataStruct = map<id, sobject>(); return Database.getQueryLocator(q); } global void execute(Database.BatchableContext BC, list<Item__History> scope) { dataStruct = batchClass_tools.processScope(scope, dataStruct); } global void finish(Database.BatchableContext BC) { insert dataStruct.values(); } }
And Your dataStruct is contained all the records
Perform your DML in execute method as shown below