Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

...

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 are 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. After-Save Flows release notes and other Flow enhancement release notes. 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).

...

  • Display Validation Rules correctly. Geezus. Who ever thought the current way Flows fail with a validation rule is acceptable? Still not good in Spring Winter '2122.

  • Be easily able to update data for duplicate management without having to write a trigger. Yep!

  • More clarification or less confusion over the whole “One Process Builder per Object” rule and “don’t mix Flow, Process Builder, Workflows and Triggers” rule. I don’t necessarily subscribe to these rule, but that needs a whole other post (Flows - Question Everything) and what I learn here might change my thoughts. (disclaimer: I don’t work in large enterprise orgs, so I’m only talking about small to medium sized orgs with small to medium sized complexities). This is going to be way more valid for After-Save Flows also. There is some documentation on this topic now in the Architect Decision Guides, and I have started writing about this in Flow Triggers Naming and Grouping .

  • Maybe getting away from DLRS… I love DLRS but as Andy is no longer able to support it to the extent that it needs, I’m worried about it’s longevityand now that it has been taken on by Salesforce Commons, it live son. And sometimes it’s flaky and sometimes it causes issues (again this probably needs a whole other post). I’m still going to use DLRS.

  • The “Always” updates - the fields that are like formulas but the formula is > 5000 character compile size so it needs to be an update. This is the whole basis for my Multiple ways to run Flows for multiple records talk at Japan Dreamin. Now, the caveat to this is building formulas in Flows SUCKS! even worse than building formulas in Process Builder! This is NOT addressed yet as at Spring '21Winter '22. However Salesforce Enhanced Formula Editor can now be used in a limited way in Flows.

  • Make it easy to do a criteria like “If all of these fields are not entered then don’t allow the stage to be changed”. When you can’t fit all of your criteria into a formula this becomes a pain to manage because you have to manage both setting the validation field AND clearing the validation field when the record is subsequently edited to NOT match the validation. I need to do another post on this - currently working on something.

Things we are still going to need Process Builder or

...

Workflow for

  • After Update queries (obvs)

  • Chatter Posts, Notifications and Email Alerts

  • Platform Events

  • Subflows!!! (Not Possible with After-Save Flows!)

  • Workflows on Long Text or Rich Text Areas (see below)

  • Creating new related records or updating related records

  • Invocable Actions

...

  • Time-based Workflow

    • The implementation of time based updates in Flows is terrible. If it has less features and is less reliable and is less customisation than existing functionality why would I use it? It is just bad.

  • Email Alerts, if there are a lot of emails being automated

    • Who’s stupid idea was it to have seemingly orphaned email alerts because you can’t see that they are used in Process Builders? And it’s not even in the new Where is it Used functionality.

    • Email Alerts can now use Lightning Email Templates in Spring '21 but they are still orphaned in the UI!

  • Where a complex formula is used more than once

    • Nope, Invocable Process Builders are just a waste of time, and see above re formulas in Flows… I sometimes just want to stick with what I know works. (May be less of an issue with the ability to run Apex in Flows, and the release of the Automation Components).

  • Long Text and Rich Text Fields

    • You STILL cannot build record triggered flows that are triggered based on the contents of a long text or rich text field. Eg I have a field named Instructions and another field named InstructionsExcerpt that is used to validate if Instructions is filled in. InstructionsExcerpt is updated every time the Instructions is Edited and IF it is not null. This will stay as a workflow. You need to have an after-save flow that is triggered ALWAYS, then include a decision in that Flow. I’m not sure it’s worth it unless you have another Always After Save Flow.

    • Foiled again! Dammit!

  • Just because

    • Why would I rebuild anything that is already fully functioning in Workflows… (nice to see this reiterated by Jen Lee in the Architect blog post)

...

  • So we have a process that needs to update some values, create some records, notify another user, add a chatter post to the record and send an email. So we are going to have the updates in the Before-Save Flows then have the rest of the bits in After-Save Flows… Isn’t this breaking the rules? Well maybe not, since Before-Save flows have their own place in the Order Of Execution before everything so it’s almost like we are removing the load of those updates from the Process Builders… but is it still going to be slow because of all the other things? The updates would not be a heavy load on the whole transaction in that scenario. (But we can do things in Process Builder to mitigate this now, like using the 0 hours wait time to almost do a “@Future” method but in Process Builder or Flownow use Asynchronous After-Save Flows so this may be a good option here).

  • Think of the classic scenario why they told us that Process Builders were sooo much better than Workflow Rules - where you have different field values based on different criteria. So I have exactly this scenario. I have 6 fields that can be different values based on one field that has 7 different options - basically it's a picklist with a list of presets and you choose that and it goes and sets all these other fields with the right values that make an external system function. Am I going to have to do all those combinations in one formula in Flow? No, decisions in Before Save Flow should do the trick now.

  • Does “Where is this Used” work for Assignment Elements in Flow? (I don’t think so).

  • Are Flow Triggers bulkified? I don’t see how they are when they run once for every single record. Check the Architect Decision Guides on this…

...

Issues with Before-Save Flows

  • You can’t Debug EVERYTHING in Record triggered Flows!!!!

    • Make sure when you are debugging that you have turned off ALL other Flows, Process Builders, Workflows etc that may cause things to not work right.

    • In Spring ‘21 there is now a debug link from the email alert on failed Flows… it’s good. But debugging directly would be betterYou can’t select an Email in the Flow Debugger (why is it a selection box rather than a text box).

Tip

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!

  • The full value of a record is in the Debug Log… now this would be the same if you added all field value variables but it is a bit of an eye opener and makes you definitely think about the data security of your debug logs - especially if you are using things like the Debugging in SFDX options.

  • Wow. Having to select the $Record with a mouse (I can’t find a keyboard shortcut to quickly expand it and start typing the field name), is such a PITA.

    • Of course this is an issue with ALL flows, and is one of the things that makes me hate flows, and makes me hate building formulas in flows,

  • You can’t use CMDT in Formulas… it’s so bad I would say don’t bother doing anything with CMDT… leave them in Process Builder.

    • So there is a work-around but it requires completely rethinking your CMDT - ensure the CMDT has enough fields to be able to select the right record with a Get Records that returns only one record. Then you can get the fields from that CMDT record.

...

  • Naming Convention: See Flow Triggers Naming and Grouping for tips on Naming your Flows

  • Ensure you don’t accidentally assign a value that will ALWAYS set the value to that and will never allow the value to be set to anything else. Eg as shown in the Release Demo Video for Before-Save Flows!

  • Create a Checkbox on your record (eg Disable Auto Update for Before-Save Flows), default False… Set this as the first Condition in your Flow… just in case you need a way to opt out. (or use CMDT or Custom Settings. See Monica’s best practice video).

  • Are there fields that always should be entered? If so, put these into a Before-Save Flow for Create only, rather than running this each time it’s updated (except if it changes of course - this is more for default values).

  • You can maybe turn off field required-ness on create for some fields that you can now set through these flows. (or event better, requiredness may be able to be set through Dynamic Forms and Dynamic Actions)

  • If you are doing a Before Create and Before Update in the same Flow then ensure you use a Decision Element before you do a Get Records on a related Object, so your flow does not fail when that lookup field is not filled in (or when the value is cleared in an Update).

  • Decide what happens after the record gets to a certain status - eg Closed Won Opp, or Closed Case. Do these flows run then?

    • Duplicate the Final Assignment Element, stick a Decision before it for the Status / Stage and only set those values that MUST be changed after that Status / Stage.

    • Or use a Lock Record Flow Action on a regular Flow to lock the record (hmm, if Before-Save runs before even Before triggers, does the regular record lock feature even prevent Before-Save updates from happening? And how does Lock Record work if Flows are run in System Context - all this needs to be tested, do not take my word for it).

  • Turn a Before-Save Flow conditionally into a Before Update or Before Create by checking for the existence of the $Record.Id. Rather than maintaining two flows… maybe… check if it slows things down.

  • Check your formulas for what happens when there is a null value. The resulting field will be Null. Do you want it to be null or 0.

...

  • You CAN NOT use formulas that include values from any other field set by the Before-Save record. Think of the field as being null always and every time you edit the record this field value is going to be set again. Note, I need to check this now that I’ve worked out you CAN use formulas in Before-Save flows. Oh wow, it looks like it works!!! See Formulas in Flow Triggers for more details on this

Info

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.

...

Issues with After-Save Flows

  • No Sub Flows

  • Runs even if nothing changes on the record (does triggers do this?)

...

  • When to use Created or Created and Updated as separate Flows?

    • Without Subflows it’s difficult.

  • How will they work bulkified when the flow only runs on one record at a time.

  • Are we still only meant to do one Flow per Object? As per above questions.

  • How do all the new Flows Permissions affect all this?

...

  • Pause or Wait in Flow - yes there is definitely valid reasons to use this in headless flows - eg using the 0 minutes wait trick to do things in another transaction.

    • Workaround may be to use Invocable Apex or the new Asynchronous Flow Path

  • Where I call a Flow - eg assigning a Topic to a record, I have that in a generic Flow - I would have to make that an Invocable Apex instead. Quip Actions (I haven’t used them but I can’t see them in Flows).

More to be added here!