1

In a context of a company that aim to expand its activities, is it a good idea to build an architecture by including declarative tools such as processes and flows?

Are declarative tools used in large companies next to apex triggers?

I know one hindrance could be the SOQL governor limit as declarative tools could cause the before and after triggers to execute multiple times.

1
  • To a scale of a typical SF customer - yes, they are. Your scale mileage may vary, aka caveat emptor.
    – identigral
    Apr 14, 2022 at 18:23

2 Answers 2

3

The general guidelines are as follows.

First, consider if you need code. If a Flow can implement 100% of the business logic, there's no reason not to use it. Keep in mind that there are now Before Save Flows for implementing changes to data as it comes in, and Record-Triggered Flows for updating related objects, scheduling future actions, sending emails, etc.

Second, do not mix declarative and code solutions on the same object. As you thought of already, recursive updates from declarative configurations can cause triggers to run twice, potentially doubling CPU, SOSL, SOQL, and/or DML usage. By strictly adhering to the "one-or-the-other" rule per object eliminates this possibility. In addition, it is relatively more challenging to figure out where a specific behavior is coming from if you have both Flows and Triggers on the same object.

Note, however, that these are just guidelines. You may find exceptions to the rule that you find acceptable. A Before Save Flow and a After Save Trigger might be an appropriate solution. Or maybe you might employ a Before Save Trigger for some kind of validation and a Record-Triggered Flow to update related records. If you decide to mix features this way, make sure it is documented. Granted, documentation should be done anyways, but especially note which behaviors come from where if you mix the two.

2

To add to the existing answer, Flows are the declarative tool mostly considered (end-of-life timeframe set for Workflow Rules & Process Builder). With Flows, your example of risk of recursive behavior is no longer any different than with Apex - just a consideration of order of operations and you have the flexibility to implement it efficiently (before or after).

In terms of scaling, I think there's a couple considerations:

Yes, you could work around it ("pause" element) to separate the transaction - but, this is another reason to carefully consider when you use for loops and the # of records you may be dealing with.

  • Consider whether it's ideal to even use a declarative tool

This might seem "obvious" and repeating the other answer, but you can typically find workarounds to do things strictly in Flow and think it might be worth it simply because it avoids code. The Record-Triggered Automation guide contains great information on flow runtime behavior as well as what it's not designed well to do. The scenarios noted

  • Adding Custom Validation Errors
  • Complex List Processing
  • High-Performance Batch Processing
    • Defining and evaluating complicated logical expressions or formulas.
      • Flow’s formula engine sporadically exhibits poor performance when resolving extremely complex formulas. This issue is exacerbated in batch use cases because formulas are currently both compiled and resolved serially during runtime.

    • Complex list processing, loading and transforming data from large numbers of records, looping over loops of loops.
      • Loops are executed serially during runtime, even during batch processing. For this reason, any SOQL or DML operations which are enclosed within a loop are not bulkified, and add risk that the corresponding transaction Governor limits will be exceeded.

    • Anything requiring Map-like or Set-like functionalities.
    • Transaction savepoints
1
  • 1
    another way of putting some of these restrictions in "flow" terms is - one Flow Interview can't influence/inspect a second Flow Interview in a transaction of arity 2+ without escaping to invocable apex.
    – cropredy
    Apr 18, 2022 at 0:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .