In this session we will talk about how to handle exception/error in Salesforce flow using fault connectors and Platform events framework.
- Flows Use Cases
- Exception Handling & Logging
- Exception Object & Fault Connectors
- Transaction Behavior
- How Platform Events Helps
Exception Handling & Logging
- Exception Unexpected event occurred during your transaction execution
- Exception Handling Deal with unexpected Exception
- Exception Logging Store exception details for later analysis and trouble shooting
Let see how to handle exceptions in a flow using fault connector, and what will be the transaction behavior after adding a fault connector to the flow.
Suppose we have one flow which updating Account with contacts country. like below which invoked from process builder.
Create Exception Scenario
Let try to add some exception with the help of validation rule. Let us add a validation rule under Account which makes Account Number mandatory on Account update.
Now if account number is missing on account record then our flow will fail. Now let see how we can handle this exception.
Handle & Log Exception – Exception Object
As a best practice, Lets try to log all exceptions in an Exception custom Object.
How to handle Exception in a flow?
To handle Exception, we need to add a fault connector to the record update operation as shown below.
What is Fault Connector : Identifies which element to execute when the previous element results in an error
Let see what will happened after adding flow connector ?
Handle & Log Exception – Transaction Behavior
- Contact Creation is success
- Account Country is not populated
- Exception Record Got Created
- Similar to try-catch in Apex
Handle & Log Exception – Throw Exception
What about if you want to fail the complete transaction ? But we have seen that we have a fault connector – transaction will be a success.
- No standard Approach in Flow
- Make use of Apex Throw exception
In Apex classes you have an option to throw exception after catching and logging error details. So let us see if we can add that behavior to a flow. We can use the invocable Apex method, which can throw our flow exception.
This issue can be solved by logging exception using Platform events
Exception Logging – Platform events
Platform events – Publish Behavior
Why we need PE & Exception Object?
PE does not provide:
- Formula fields for additional processing
Scenario 2) Screen flow – Exception Logginig
If the Account type is Partner Account – Display a screen to enter additional details by user and based on entered values, decide Account Partnership level as Diamond, Gold or Silver
Screenflow – Exception Logginig using FlowExecutionErrorEvent
- FlowExecutionErrorEvent – Standard Platform event from Salesforce
- Salesforce publish event to this when a screen flow fails
- We can subscribe to this and log Exception
Comparison between Custom Platform event and FlowExecutionErrorEvent approach for Exception Logging
|Date : Sat, AUG 05, 2020 10:00 AM EST (7:30 PM IST)|
Where : YouTube
Speaker : Meera Nair
Thanks Meera Nair for sharing your knowledge with us.
7,230 total views, 27 views today