How to throw exceptions in Flows?
Hi! 😀
In this article, we shall learn how you can throw your own custom exceptions in Flows.
How to get started?
It’s fairly simple. First you have to create an Apex class that extends Exception class and then create an Invocable method inside the same class which simply throws an exception. FlowApexActionException.apxc
/* Class definition for throwing custom exceptions via Apex actions in Flows */ public class FlowCustomError { public class CustomException extends Exception {} @InvocableMethod(label='Throw Custom Flow Exception') public static void throwCustomFlowException(Inputs[] input){ throw createCustomException(input[0].message); } public class Inputs{ @InvocableVariable(label='Error message') public string message; } static CustomException createCustomException(String message) { CustomException ex = new CustomException(message); ex.setMessage(message); return ex; } }
Inputs for the actions
– Error message: A text type input. Pass the custom error message of your choice in this input.
For the ease of installation, I created a unmanaged package that you can install directly from this link: https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6F00000416JL
If you want to review the package components and code, you can refer to this Github repo: https://github.com/forcePanda/Flow-Repo/tree/master/Apex%20Actions/FlowCustomExceptionApexAction
Hope you find it useful! ✌
Thank you for being an awesome reader! Subscribe to this blog for receiving all the latest updates straight to your inbox. 🙂

.png)




Comments