I came across an interesting question on Trailhead that’s worth sharing. A Salesforce user was trying to use a Record-Triggered Flow with a Custom Error element, but they also wanted to keep creating records even if an error occurred. For example, you might want to log a task to follow up on the error or create an error record to track errors outside of setup. The problem? The Custom Error element’s default behavior rolls back the entire transaction, which stops any and all record creation. This is a pretty common need in Salesforce, combining on-screen error alerts with backend error logging. Luckily, there’s a straightforward, no-code solution that can handle this setup without compromising Flow behavior.
At a high level, this approach uses a platform event that publishes regardless of the rollback status of the original Flow. We can then subscribe to that platform event in a subsequent Record Triggered Flow, which allows us to continue the transaction and make the changes to records we need to make. Here are some steps to take to set this up:
Step 1: Create a platform event in Setup
Head to Setup>Quick Find>Platform Events>New Platform Event
Click Save
In 'Custom Fields and Relationships', add whichever fields you want to carry over from your original Record Triggered Flow. For mine, I will add the Record Id of the Account that Triggered my Flow.
Step 2: Create the Platform event in your Flow
In Setup>Quick Find>Flows either create a new Flow or navigate to the Flow you have that contains an error element you want to persist.
My Flow is set to block Accounts that have been named "Test", and will surface the message "Test Accounts aren't allowed in this Org" via the Custom Error element. Directly after that, we will create our Platform Event.
Save and activate your Flow
Step 3: Create a new Record Triggered Flow, that is subscribed to your Platform Event
From Flows, select New Flow>Start From Scratch>Platform Event-Triggered Flow
Select the platform event type you created to subscribe to:
Add the logic you need in your follow-up Flow. In mine, I am getting the Account record from the platform event and updating its type value.
Save and Activate
And that's it! Your Platform Event Triggered Flow also runs in a completely separate transaction (since the Platform Event breaks up the transaction), giving you new transactional limits for your follow-up actions. This is all achievable in native Flow, without the need to go to Apex code.
If you do want to use Apex for this, you could just as easily use an Invokable method that queues a queueable, which can then perform the actions itself or call another piece of automation.