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
Alesia Dvorkina 11Alesia Dvorkina 11 

MIXED_DML_OPERATION in an Autolaunched Flow

I am working on a flow that would create a Contact when a new User (UserType = Standard) is created.

I am getting the following error:
An error occurred at element Create_Contact (FlowRecordCreate).
INSERT --- INSERT FAILED --- ERRORS : (MIXED_DML_OPERATION) DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): Contact, original object: User, 


I have researched and found out that this is a common error when trying to perform DML operations on non-setup (Contact) and setup (User) objects. The solution for those who encountered this error from a Trigger is to split DML operations into future and non future context (perform DML on Non-Setup object type, then perform DML on Setup object type in @future methods). 

How can I apply this logic to a Flow used in a Process? Any ideas? Thanks in advance for help!

Best Answer chosen by Alesia Dvorkina 11
Alesia Dvorkina 11Alesia Dvorkina 11
Thank you both for your time and your replies!
@Carlos - I believe we are getting different results, since my Process is using a Flow, instead of the Action, since there's quite a lot of logic behind it (if statements and loops) that a flow cannot handle.
@James - creating multiple processes and multiple flows was my "last resort" solution (as creating a Trigger is not an option for me :) - it would take me weeks). But before I rebuilt my flow, I have decided to contact Salesforce Support and luckily :) got a very knowledgeable representative, who already dealt with this type of scenario. 
Here is the solution:
In the process I used a Criteria of "No criteria - just execute the actions!" and for the Action I had my Flow that handled all of the logic. What I needed to do is to add some sort of criteria ("Conditions are met" or "Formula") and then add my Flow as an Action for Scheduled Actions, instead of Immediate Actions. Since I needed to execute my flow as soon as possible and the smallest time parameter is "1 Hour", the rep suggested to add a Time Schedule as "1 Hours BEFORE User.Last Modified Date (or use any other field you need)". It worked beautifully. So in Flows, equivalent of "@future" is a Scheduled Action.
I hope this helps to whoever else runs into this issue!

 

All Answers

James LoghryJames Loghry
Unfortunately, you'll need to be creative with a solution here as there is no direct way to handle this error in a flow.  For instance, you could create a a second Process that fires when a custom field is updated (via your original Process), and then use the Second process to create your Contact record as highlighted in this blog: http://www.snugsfbay.com/2014/06/avoid-flow-trigger-errors-associated.html

Otherwise, you'll have to implement the logic in a trigger and use the future method as you have already mentioned.
Carlos Campillo GallegoCarlos Campillo Gallego
Hi Alesia,

I have just try to reproduce the behavior you explain using process builder and "sadly" I have created the contact record without any problem...
User-added image
As you can see, the record creation is quite simple. The criteria diamond just checks a checkbox field value in order to trigger the contact record creation.
I'm not sure if this is the same scenario you are experiencing, so please let me know if I can help you further.

Regards,
Alesia Dvorkina 11Alesia Dvorkina 11
Thank you both for your time and your replies!
@Carlos - I believe we are getting different results, since my Process is using a Flow, instead of the Action, since there's quite a lot of logic behind it (if statements and loops) that a flow cannot handle.
@James - creating multiple processes and multiple flows was my "last resort" solution (as creating a Trigger is not an option for me :) - it would take me weeks). But before I rebuilt my flow, I have decided to contact Salesforce Support and luckily :) got a very knowledgeable representative, who already dealt with this type of scenario. 
Here is the solution:
In the process I used a Criteria of "No criteria - just execute the actions!" and for the Action I had my Flow that handled all of the logic. What I needed to do is to add some sort of criteria ("Conditions are met" or "Formula") and then add my Flow as an Action for Scheduled Actions, instead of Immediate Actions. Since I needed to execute my flow as soon as possible and the smallest time parameter is "1 Hour", the rep suggested to add a Time Schedule as "1 Hours BEFORE User.Last Modified Date (or use any other field you need)". It worked beautifully. So in Flows, equivalent of "@future" is a Scheduled Action.
I hope this helps to whoever else runs into this issue!

 
This was selected as the best answer