function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC_KMSFDC_KM 

FATAL_ERROR: System.UnexpectedException: commits are not allowed because someone called setCommitAllowed(false), justification: doWorkAndCommit

I am calling a batch in trigger where I a, getting 'System.UnexpectedException: commits are not allowed because someone called setCommitAllowed(false), justification: doWorkAndCommit' error while bulk update. In debug logs the error is indicated for line no underlined below.
if ([SELECT count() FROM AsyncApexJob WHERE JobType='BatchApex' AND (Status = 'Processing' OR Status = 'Preparing' OR Status = 'Queued')] < 5){
    ID batchprocessid = Database.executeBatch(new batchClass(contactsId),100);
} else{
        ID batchprocessid = Database.executeBatch(new batchClass(contactsId),100);
        Boolean isSuccess = System.FlexQueue.moveJobToFront(batchprocessid);
        system.debug('---batchprocessid: '+batchprocessid+' & movedToFront: '+isSuccess);
}

Can anyone lead me to the reason for this exception?
 
Raja Bipin Chandra  M BRaja Bipin Chandra M B
Hi, were you able to fix this issue? Can you please share the solution if fixed?

Regards,
Raja