I have a scenario where I insert orderItem records using a batch class. I have an after insert trigger on OrderItem that calls a batch to update on other object.
I'm getting an error
"System.AsyncException: Database.executeBatch cannot be called from a batch start, batch ..."
when after insert trigger fires.
It doesnt give me an error when i put this in trigger code,
if(trigger.new !=null && trigger.new.size() > 0 &&!system.isFuture() && !system.isbatch()){
Database.executeBatch(new UpdateSubProductsBatch(trigger.new),500);
}
but doesn't execute the batch from trigger.
If I take off the !system.isbatch()
from if conditions, its gives me the above error.
Can you please help me in understanding the situation and how to deal with it.
I am using the batch after the after insert trigger, because i have to update bulk records.
orderItem
? from batch i think?UpdateSubProductsBatch
batch from trigger.. instead when your first batch completed, callUpdateSubProductsBatch
method from first batch's finish method.