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
Michael DenteMichael Dente 

DML Operation on setup object is not permitted after updating a non-setup object?

When attempting to delete a product from an order I get this :DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): CustomFieldDefinition, original object: OrderItem

In the past I was able to do this so im not sure what is causing the issue. Any advice would be much appreciated. 
VinayVinay (Salesforce Developers) 
Hi Michael,

There are few objects which cannot be used together when performing DML operations, use a Future method to perform the DML operations.

https://help.salesforce.com/s/articleView?id=000325253&type=1

Please mark as Best Answer if above information was helpful.

Thanks,
mukesh guptamukesh gupta
Hi Michael,


There you cannot perform DML on what salesforce calls setup objects(User,Profile,Group,RecordType in this case) and non-setup object in the same context. There is a workaround that can be found here although I still had some issues. 

https://help.salesforce.com/articleView?id=000315345&type=1&mode=1 (https://help.salesforce.com/articleView?id=000315345&type=1&mode=1)
Check the workarounds as mentioned in the above official article.


For further reference, you can check the below,
https://developer.salesforce.com/forums/?id=906F00000008wAZIAY


if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh