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
sai.sfsai.sf 

DML operation on setup object is not permitted after you have updated a non-setup object

I am getting this error in batch apex  "DML operation on setup object is not permitted after you have updated a non-setup object  ".


How to fix this.

Best Answer chosen by Admin (Salesforce Developers) 
sai.sfsai.sf

I got the solution by making the update in 2nd batch apex and calling the 2nd batch apex from finish method of 1st batch.

All Answers

Laxman RaoLaxman Rao

To avoid the above error generally we use @future method.But you are getting this error in batch class.

So we cannot call a @future method in batch.

 

Unfortunately the workaround is going to be avoiding using batch or update the setup object manually after running the batch.

 

Mixed DML 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dml_non_mix_sobjects.htm

 

Batch best Practices

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch_interface.htm

sai.sfsai.sf

I got the solution by making the update in 2nd batch apex and calling the 2nd batch apex from finish method of 1st batch.

This was selected as the best answer