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
SalesRedSalesRed 

Test Class Error: CANNOT_EXECUTE_FLOW_TRIGGER

Hi,  I receive the following error in a test class but have not been able to repeat them in non test running scenarios.

"System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_EXECUTE_FLOW_TRIGGER, The record couldn’t be saved because it failed to trigger a flow. 
A flow trigger failed to execute the flow with version ID 301O00000008hM6. 
Contact your administrator for help.: []"

Does anyone know if there could be an issue running flows in test class contexts but not otherwise?

Thanks.
sivaextsivaext
Hi, 

Check the below link, might help in this scenario

https://success.salesforce.com/issues_view?id=a1p30000000T3sCAAS

Regards
Siva.
SalesRedSalesRed
, Thanks I had seen thia alright. It does not suggest a solution unfortunately though.
Michael HaaseMichael Haase
I got the same behavior when deploying new custom objects. My test class on the Task object delivers the same error message. The issue I identified: I have an active workflow from the Process Builder running on the Task object. I was able to deploy my new custom objects after I temporarily deactivated the Process. The Test Class didnt bring errors anymore at this time.
Jayesh BhatnagarJayesh Bhatnagar
I am receiving the same type of error on a Test Class related to a Process Builder. Did anybody log a case with Salesforce?
Jayesh BhatnagarJayesh Bhatnagar
Exact error message I received is below:

System.DmlException: Update failed. First exception on row 0 with id a0VA0000008l18nMAA; first error: CANNOT_EXECUTE_FLOW_TRIGGER, The record couldn’t be saved because it failed to trigger a flow. <br>A flow trigger failed to execute the flow with version ID 301A0000000CbpA. <br/> Contact your administrator for help.: [] 
Jayesh BhatnagarJayesh Bhatnagar
The workaround of disabling the Process Builder process temporarily is not viable since any Apex deployment to Production will run the test classes and fail. Requiring a disabling of the Process Builder process each time even for unrelated deployments.
SalesRedSalesRed
Hi,  I opened a case with Salesforce sometime ago about this. I was informed that it was a known issue and that a fix was being applied (some weeks ago at this stage).  For my purposes i was able to get around the issue by disabling flows before deploying classes. Not a good solution I know.
Francisco Riccomagno 1Francisco Riccomagno 1
Any update on this? I'm having this issue when trying to run some apex unit test that fire a process builder task.
Krish RavichandranKrish Ravichandran
Any update regarding this issue?
Carter85Carter85
Same issues, any update?  This is getting to be beyond frustrating at this point in terms of unrelated deployments.
Egor VolkovEgor Volkov
Looks like this issue was fixed https://success.salesforce.com/issues_view?id=a1p30000000T3sCAAS
RAJENDER ADAMALARAJENDER ADAMALA
I am facing the same issue in my test class. can you please provide me the update on resolution?  
Daniel Sadavoy 14Daniel Sadavoy 14
Same here. What a downer. 
Kapil GoutamKapil Goutam
Hi You have to add system.run as in your test class code. Here is how I get it fixed
User usr1 = TestUtilClass.insertUser();
 system.runAs(usr1){
   //put your test code here
}

This should fixed the issue.
bobnunny1bobnunny1
I already have runAs and still receive this.  TO make it worse, it happens in one sandbox and not another.
 
Servicewise ExternalServicewise External
We get the same issue. Anyone sucedeed to get more specific error messages? There is no way to quess what is the problem.
Kapil GoutamKapil Goutam
Can you check, the user which you are insrting is system admin profile? I believe if you insert a worker as system admin & then add runAs it should resolve the issue. Thanks!
Servicewise ExternalServicewise External
Shoud I specify in my test class code the user who runs it? If so, how can I do it? 
Isn't the default running user is my admin user?
Kapil GoutamKapil Goutam
Yes, you should do something like this -
Profile profile = [Select Id From Profile where Name = 'System Administrator' limit 1];
User usr1= new User();
usr1.ProfileID = profile.Id;
//all other required field.
insert usr1;
System.runAs(usr1){
}
André BartieresAndré Bartieres
I have the same problem, but not test class, the System.runAs command works only for certain tests? how to solve this problem in the implementation process? Please help me.

Thank you.
sean*harrisonsean*harrison
Getting same error executing tests. Using runAs() has no positive effect. 
Sekar RamamurthySekar Ramamurthy
If anyone is still looking for an answer in this thread... here you go.

You might get this error if the SObject (that you're inserting in Test class) has an active Process Builder that expects certain fields to have values and those field values are NOT supplied in the test data before inserting them.

Try to pack all the necessary fields for the SObject that are required by process builder. You don't need to deactivate the process builder to run test successfully.

If you have record types set for that SObject make sure you supply the appropriate record type in the test data preperation as well.

 
cloudstreamercloudstreamer
Thanks. Once I set the fields used in the process conditions and actions in the test data, the error is resolved
Saheli ChatterjeeSaheli Chatterjee
@Sekar- My test class only uses custom metadata . Hence there is no Process Builder on any particular sObject . What could be my reason . The stack trace also shows failure in the test user creation method.
Rohith Raj Chenna 1Rohith Raj Chenna 1
@Sekar Ramamurthy- Thank you. Your answer solved my problem. Upvoted.
textualtextual
oh, so activating a process builder flow has the potentional to break all of your test classes that use the same sObject? fantastic. and now i need to scramble to update any class that uses that object? wonderful. thanks guys! i was hoping to thrash at tasks thats suposed to take an hour but turn into multiple days. thats a great ROI benefit that was never mentioned before
JotacheJotache
Hi everybody, i get an similar error when execute a web service that create opportunities with classes apex. But in some cases opportunities was save successfully and others not. Can you help me please?
Jennifer ChisholmJennifer Chisholm
I just experienced this problem in the same set of circumstances.  Did you ever get it resolved?
Michiel van FeliusMichiel van Felius
Thx Sekar Ramamurthy. Your answer solved my problem. 

To find the flow (by version ID) which causes the problem, you can use workbench (workbench.developerforce.com). 
Goto Workbench > Utilities > REST Explorer > Execute a GET request with this path (/services/data/v41.0/tooling/sobjects/flow/{FlowVersionId})
Faujiya Mandrupkar 12Faujiya Mandrupkar 12
Thanks Sekar...I added the fields used in process builder condition in my test class and the test class code coverage is 100% now :) 
Pavan Kumar 1072Pavan Kumar 1072
In my Scenario, Multiple processes are failed on Case object If I run test classes related to case object.Mostly I'm the owner of these process.
So, I got an email whenever any process fails.When i  debug these email's process are failed due to various reasons.

I Inspected my logs step-by-step then I found my problem is triggers are running multiple times.
So, I hit exceptions like 101 SOQL, CPU time Limit.

By using Static variable's, I restricted my classes to run only one time in a single transaction.
Still, if you face these error's check your process if it has many conditions & If it has criteria like Created & everytime edited then it takes so much to execute.My suggestion is to simply process like run only with specific record types & custom criteria  
  
Qiuzhen CaiQiuzhen Cai
Sekar Ramamurthy's answer works for me. Thank you!
Todd KadasTodd Kadas
Also, make sure that the field values in your test class don't match the process builder criteria.  This might be obvious to some but that's what was causing mine to fail
sanjayrs23sanjayrs23
I had the same issue, I found there was no dependency with the process builder. So looks like there are multiple issues with Flow deployment and all the above scenarios could be the valid one. 
In my case, some of the fields were missing in the test class itself which were used in Flow and setting those values resolved the issue.