6

Prelude

We have a button on the Account object which kicks off a Flow whose only job is to call an Apex Action. Inside the invocable Apex class, there is much weeping and gnashing of teeth, after which a new unique Account Number is generated.

We do the work inside an Apex class for two main reasons:

  1. It is very complex
  2. It needs to also be called from some automated process, not just from the UI

Within the Apex we are throwing some custom Exceptions (of one type) if certain different criteria are not met for generating an Account Number.

For now we have this...

enter image description here

...which allows us to access and display the {!$Flow.FaultMessage}.

This is better than not doing that, but it is still quite inelegant, as it looks like this:

enter image description here

The users do not know what an Apex error or an AccountException is. At best it is ugly; at worst it will confuse some users and cause unneeded ticket creation.

So at the very least, if possible, I would like to remove that prefixing information.

But at the arrow end of the Fault connector, there is nothing I can access except for {!$Flow.FaultMessage} that gives me any access to the Apex exception.


Further Thoughts

I assume that we could send the Fault output to a Decision step and use it to try to parse the text of the {!$Flow.FaultMessage}. But that seems QUITE cumbersome and probably not worth the effort.

If we could access the exception object itself within the Flow, like you can within Apex, to be able to use the Exception methods (e.g., getCause(), getMessage(), getTypeName()), that would be ideal.


Question

Is there any way that I am missing where we can access the actual Apex exception inside the Flow to more elegantly handle and display our exceptions?


EDIT/UPDATE AFTER INITIAL POSTING

I just read this question which did not show up on the radar in my earlier pre-question search because it did not involve exceptions. @sfdx's answer talks of InvocableVariables.

Would that be a potential solution?

The Salesforce documentation states

The data type of the invocable variable must be one of the following:

  • List item
  • A primitive
  • An sObject, either the generic sObject or a specific sObject
  • A list or a list of lists of primitives, sObjects, objects created from Apex classes, or collections

Does this mean we could create a List<CustomException> invocable variable that could be accessed in the Flow?

1
  • I believe if you catch the exception in your apex code you can return a list of exceptions to the flow. Then only an uncaught exception would go down the fault connector.
    – gorav
    Commented Jun 5, 2020 at 10:50

0

You must log in to answer this question.

Browse other questions tagged .