Ho-ho-ho! Christmas is just around the corner and it is time for another little tip from our #TexeiAdventCalendar! Today we are going to speak about Mixed DML.
I hope you had a great time yesterday with Daniel Lopes’ article. Just in case you missed it, you can find it here learn what’s new for LWC in Winter 21.
![Mixed DML](https://texei.com/dev/wp-content/uploads/2020/12/1_rjYhcf1QJsBlIuvEtiZrPQ.gif)
Debugging Flows and Process Builder can be tricky and painful. Even with the recent addition of the debugging mode in the Flow Builder. So today, I’ll give you a quick tip: how to avoid getting a “Mixed DML operation error” in your Flows and Processes.
A Mixed DML operation error occurs when you try to persist in the same transaction. Changes to a Setup Object and a non-Setup Object. For example, if you try to update an Opportunity record and a User record at the same time.
How to avoid this?
It’s pretty easy, you just need to make sure that these operations take place in different transactions. Which means adding an element or a process to close the first transaction.
- In the Process Builder, the trick is: move your actions in scheduled actions that will be executed 0 hours from now. Basically the same as immediate actions.
- In an Autolaunched Flow, you can just insert a Pause Element.
- Finally, in a Screen Flow, organize your flow. So that your actions are either separated by a Screen Element or by a Local Action.
Hope you had a good read about Mixed DML! Come back tomorrow for a new article written by Fabien Taillon. And if you don’t want to wait, you can go to https://texei.com to see more content. Follow us on LinkedIn here and on Twitter here!