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
debradebra 

MIXED_DML_OPERATION error on delete orderitem records not doing any setup DML???

I have a VF page with controller extension that allows users to add/delete/edit OrderItem records in a grid like layout.
The only DML operations included in the controller are to delete or upsert OrderItem records.  However when the delete operation is called I get the following error:
Apex script unhandled exception by user/organization: 005E0000000kS6z/00DS0000001xNZE Source organization: 00DE0000000c2W5 (null) Visualforce Page: /apex/orderItemEntry
 caused by: System.DmlException: Delete failed. First exception on row 0 with id 802S00000008RygIAE; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): CustomFieldDefinition, original object: OrderItem: []
--------------------
Also here is an extract from the debug log showing the list passed to delete does contain a valid entry for deletion:
14:23:57.0 (105132099)|USER_DEBUG|[184]|DEBUG|DEBUG  DELETE LIST = (OrderItem:{Id=802S00000008RygIAE})
14:23:57.0 (105148186)|STATEMENT_EXECUTE|[185]
14:23:57.0 (105237697)|DML_BEGIN|[185]|Op:Delete|Type:SObject|Rows:1
14:23:57.0 (105252033)|LIMIT_USAGE|[185]|DML|1|150
14:23:57.0 (105267176)|LIMIT_USAGE|[185]|DML_ROWS|1|10000
14:23:57.0 (105287337)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
14:23:57.0 (267282230)|DML_END|[185]
14:23:57.0 (267459888)|EXCEPTION_THROWN|[185]|System.DmlException: Delete failed. First exception on row 0 with id 802S00000008RygIAE; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): CustomFieldDefinition, original object: OrderItem: []


-----------------------------------
Is there possibly some type of hidden or unexpected setup object DML that could occur with VF page using standard Controller (Order) with controller extension?   There is some code in the controller to retrieve (Select only no DML)  the pricebook for the Order but nothing related to setup objects like User, etc...
SandhyaSandhya (Salesforce Developers) 
Hi,

My guess would be that there may be other events within the same transaction (such as a trigger) that is updating a custom field somewhere. And therefore causing a Mixed DML operation to take place.
 
I would suggest running the update from execute anonymous in the developer console, and checking the debug logs to see if any triggers or workflows, etc... are been called after the update of these records.


Also please refer below links which have a similar discussion that can help you!

http://salesforce.stackexchange.com/questions/13318/error-mixed-dml-operation-on-setup-and-non-setup-objects
 
https://developer.salesforce.com/forums/?id=906F0000000941vIAA
 
http://www.tgerm.com/2012/04/mixeddmloperation-dml-operation-on.html
 
Hope this helps you!

Please mark it as Best Answer if my reply was helpful. It will make it available for other as the proper solution.
 
Thanks and Regards
Sandhya