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
NicGallerNicGaller 

Error handling for Visual Flow started from Apex

Hello all,

I have recently started using Visual Workflows to replace regular workflow and Apex code.  In general I like it, though they can be hard to troubleshoot they are a lot easier to put together and for the end user to manage.

Here is a problem I am having with a flow I use to submit opportunities.  The process is submitted from Apex code - this can run either from a trigger or a VisualForce page.  Basically the flow has some custom logic to figure out if the opportunity is eligible to submit, then it launches the submission using a "Submit for Approval" element.  There is more logic going on in the approval process entry criteria and if the opportunity does not match it will give an error "No applicable approval process was found".  What I would like is to capture this error into an output variable of my flow.  If it was started from the VF page, I can capture the output variable and show it to the user.  If it was started from the trigger I can just discard it.  And this is mostly working - I am getting the error status back in the VF page - BUT I am also still getting an "Unhandled process fault" email.  

Is there something I need to do to mark the error as "Handled" so that I do not get that email?

This is the relevant portion of my flow:

Approval flow
And this is how I invoke it:
 
Map<String,Object> params = new Map<String, Object> ();
params.put('OpportunityId', oppId);
Flow.Interview.MyFlow flow = new Flow.Interview.MyFlow(params);
flow.start();
String status = (String)flow.getVariableValue('OpportunityApprovalStatus');

Thanks!!