Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Add ability to raise exception in flow action #489

Closed
isidle opened this issue May 5, 2023 · 6 comments
Closed

Feature Request: Add ability to raise exception in flow action #489

isidle opened this issue May 5, 2023 · 6 comments
Assignees
Labels
Layer: Logger Engine Items related to the core logging engine Logging Source: Flow Items related to using Nebula Logger within Flow Type: Enhancement New feature or request

Comments

@isidle
Copy link

isidle commented May 5, 2023

When a record triggered flow runs an fault path, the execution continues instead of raising an exception & rolling back database changes.

This is particularly problematic for record triggered flows, as everything could end up in an incomplete state.

Add an optional boolean to the attributes and when true, call an exception passing the value of faultmessage.
Otherwise would need to create a separate invokable action in order to raise the exception and unwind the transaction.

@jongpie
Copy link
Owner

jongpie commented May 22, 2023

@isidle thanks for adding this idea! I think it'd be fairly easy to add this functionality into the Flow invocable methods - I'll do some additional analysis this week to see if there are any issues, but I'm hopeful that this will be a fairly easy enhancement to make.

@jongpie jongpie self-assigned this May 22, 2023
@jongpie jongpie added Type: Enhancement New feature or request Logging Source: Flow Items related to using Nebula Logger within Flow Layer: Logger Engine Items related to the core logging engine labels May 22, 2023
@JeroenSfdc
Copy link

That would be a nice addition, as today I always configure an 'Exception Thrower' invocable class in my fault branch for that purpose. It the fault could be thrown by the Nebula invocable that would be less clutter.

@JMercie
Copy link
Contributor

JMercie commented May 23, 2023

@jongpie I was investigating how to implement this, and I have a rough idea of how to make it available for the log methods in flow, but I think there's a challenge setting the Savepoint to do a rollback from Apex.

Rollback the entire set of transactions in Flow is also difficult with the standard rollback records flow component because this one will only roll back the latest pending transactions, not the ones already executed.

If you know how to do the rollback in the DB, I can help implement this!

@isidle
Copy link
Author

isidle commented May 30, 2023

Calling an exception throw new exception('something failed'); is all you need to have database unwind changes in synchronous transactions.

The only time you'd need a savepoint is if they were running both synchronous and asynchronous logic and wanting to unwind to the very start of everything but at that point the onus is on the dev to handle that as there is no way for nebula to know which transaction they wanted to roll back to.
IMO this is a very rare edge case, while 99% of the time stuff is being done in just one or the other.

@jongpie
Copy link
Owner

jongpie commented Jun 16, 2023

@JMercie sorry for the late response! If you're still interested in contributing, I'd be happy to review any code changes you make. If not, no worries, I can work on this sometime in the coming weeks.

And I agree with @isidle - just throwing an exception (after saving any pending log entries, using Logger.saveLog(Logger.SaveMethod.EVENT_BUS) should work - the exception will rollback the current transaction, without needing to use SavePoint.

@jongpie
Copy link
Owner

jongpie commented Jul 28, 2023

@isidle and @JeroenSfdc, I've just finished publishing the new release that includes this functionality - it's now available in v4.11.1. Thanks again to @JMercie for implementing this!

@jongpie jongpie closed this as completed Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Layer: Logger Engine Items related to the core logging engine Logging Source: Flow Items related to using Nebula Logger within Flow Type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants