Other Pages on Flow Triggers

Before-Save Flows - much rejoicing was had when the Spring ‘20 release notes first came out… but are they all they are cracked up to be… let’s investigate. But first, have you seen a Before-Save Flow demo video (apart from mine) that does anything more than updating one or two fields… let’s get real here, in the real world we need do to soooo much more.

After-Save Flows were also released in Summer '20. Winter 21 release had a few new features but were still not enough to move Process Builders to Flows. In Spring ‘21 Winter '22 I think we are finally there! I will update this post with tips and tricks as I migrate all my complex calculations to Flow from Process builder. (Let’s start with Percentage Fields in Flows weirdness).

What do I want Flows and Process Builder to do

Things we are still going to need Process Builder or Workflow for

Things I will still only use Workflow for…

A small sidebar…

I have a client with very complex currency calculations that of course are more than the 5000 compile size limit. We had a major structural change to the object so it was best to create a new object to refactor the database (to more closely mirror the external system we are integrating with). This was just 12 months ago so Process Builders are well entrenched and are definitely the way things are “meant” to be done.

All the formulas were basically the same. So this is a great opportunity to move everything to the recommended way of doing things right…

Well, what a nightmare. The record was so slow to save (no delay in saving the same formulas in workflow rules) that I had to severely restrict when the fields were updated, which has caused issues with people not believing the data they see… very understandable.

So now I have to either rebuild everything in flow triggers, or get right to it and code all these highly complex formulas (that do change based on government legislation changes for example. And yes, we did just have a huge change in government legislation due to Covid).

Questions before I delve in

Starting to Work

My first foray into Before-Save Flows was in a pre-release scratch org where I made a quick video about changing from a regular flow to a Before-Save Flow.

Over the next few releases I tried again, but just had to give up. I am now starting fresh in Spring '21.

Issues with Before-Save Flows

Add an Assignment element named Error as the last element in the flow. Make an error happen in this Assignment item (eg set RecordID to a blank value) and turn on the Debug Log. This saved me big time!

Example

Case({!ThisRecord.MyFieldHourOrDay__c},
"H",$CustomMetadata.MyMD__mdt.Scenario1HourID.ExID__c, "D",$CustomMetadata.MyMD__mdt.Scenario2DayID.ExID__c,
0),

It’s OK if you’ve got one of these, you can do that in a formula, but when you have 15 combinations to look through to choose the right MDT record, the formula gets too big.

IF(ISBLANK(TEXT({!$Record.YourField__c})),"Default Value,TEXT({!$Record.YourField__c}))

Good Things

Tips

My Scenario

For the Contract Fee I have a Percentage Field and a Base Rate. If the Percentage Field is not filled in I want the Contract Fee to be null. But If I enter a 0% Percentage then I DO want the Contract Fee to say $0.

In formulas this is as simple as checking the Treat Blank Fields as Blank box (or otherwise), but you have to handle it yourself in Flows.

When to use After-Save

Note: The Architect Decision Guides say DO NOT use After-Save Flows for single record field updates… this is not practical at all.

Gotchas

In my scenario above. I enter the Base Rate - it is never set in my Assignments in my Flow. I always set my Contract Fee based on the Percentage and the Base Rate.

But what if I have another formula that I want to calculate Contract Total that is added as the Base Rate plus the Contract Fee.

If the formula for fContractFee is $Record.BaseRate__c * $Record.Percentage__c

The formula for fContractTotal can not be fContractFee + $Record.BaseRate__c

It would have to be ($Record.BaseRate__c * $Record.Percentage__c) + $Record.BaseRate__c

(I’ve excluded all the null checks for clarity).

Then I have another formula that spells out the Contract Total in words to display on the Contract documents. So I would have to put the full formula calculation for every part of the formula that requires any part of the value. (For example see all these stupid formulas just for adding the dollar signs). Nope.

That’s all fine for simple formulas but for complex formulas that is a need to go into After-Save Flows.

My Scenario

On my Contract I have a field for the Signatory. The Default Signatory is set as a field on the Account. If I am creating a new Contract I always want the Default. But if they change the Signatory away from the Default, then I do NOT want this Before-Save Flow to override their choice.

If the Contract is Activated, and the Default Signatory changes on the Account, and I happen to update any field on a Contract after that, then I do NOT want the Signatory to change to the new Default Signatory from the Account, I want it to always remain as the Signatory it was set as.

So, why not do this in a Before-Save Flow only for Create… yep that is fine. But what if my Account changes before the Contract is Activated (eg the Contract needs to be for the Parent Account which is the National Office, rather than the Branch Office. If I change the Account, I ALWAYS want to set the Default Signatory again.

So this is probably where I would revert to doing a Before-Save Flow on Create, then an regular Process Builder on Is Changed… it gets too hard in a Before-Save Flow on Create and Update.

Suggestions on working through changing existing Process Builders

Not sure if any of these are valid… just trying to work through them.

After-Save Flows

Good Things

Issues with After-Save Flows

Questions for After-Save Flows

One Flow Per Object - Reasons Against

Things you still will NOT be able to use Flow Triggers for

More to be added here!