I am receiving the below error when the batch is executing. This is not happening all the time. This happens only at certain times.
uncommitted work pending. Please commit or rollback before calling out
The batch that runs performs deletion of some child records based on the flag for the passed in parent record in the batch. Then it makes a callout to receive token and then another callout to send both parent and child record. For each callout, whatever response is received that is stored in a list of log object. Then after processing all the records for callout, insert of the log object is done. Then the processed parent and child records flag is reset by update.
I have scheduled this batch to run every 3 minutes. In that only some logs have success and other logs have empty responses because of the error. Can someone help me on this?