Flow – Before Insert Trigger

As we all know, Flow is blowing up! Every release is a treasure trove of new features, and its use is expanding accordingly.

The record update triggered Flows are one of the newest features, and I thought I’d share what may be the best use case I’ve encountered to date. PS. At some point we need to all land on common nomenclature for these record-triggered flows ­čÖé

Trigger hell is a real thing, and especially so when managed packages enter the fray. This is especially true when the managed package is expecting certain values by the time it runs, including in a before insert/update context. I have encountered many scenarios where an asynchronous update is required after the initial transaction just to get a value populated and re-trigger the managed code.

An example of this is the ‘Legal Entity’ field that must be present on Order/Order Product creation for the Salesforce Billing package. The ‘Legal Entity’ is a critical field used to determine Billing, Tax and Revenue Treatments on the resultant order. The struggle is that the check for this field seems to be in the managed package before insert/update trigger, and so we couldn’t get the entry in prior to the package. This required firing off an asynchronous transaction just to fill it so the package would re-run, which was incredibly wasteful.

This is where Before Save trigger Flow comes into play. As we see in the documentation: In a save procedure, before-save updates in flows are executed immediately prior to Apex before triggers. This is critical as it means any update is guaranteed to sneak in before the managed code picks up. Sure enough, when I added logic to insert the Legal Entity in a before insert Flow, the managed package recognizes it and fires all of the expected updates in the same transactions.

Incredible news here for dealing with the intricacies of managed packages and orders of execution!

Leave a Reply

Your email address will not be published. Required fields are marked *