Sub topic 9
Maintenance cost and who owns the automation
This chapter assumes you know the Salesforce data model, can find your way around Setup, and have built a simple flow. It also assumes you understand basic programming concepts such as variables, loops, and collections. You have already seen what Apex and Flow are. Here the question is what each one costs to keep running after the first release.
Build cost is not maintenance cost
Most teams pick a tool by asking how fast they can build something. The better question is who will change it in two years, and how safely they can do it. Automation is rarely finished. Fields get renamed, business rules shift, and people leave.
Maintenance cost has four parts:
- Reading: how long it takes a new person to understand what the automation does.
- Changing: how much effort and risk a small edit carries.
- Verifying: how you confirm the change did not break anything.
- Staffing: who on the team is able to do all three.
How Flow and Apex differ
| Concern | Flow | Apex |
|---|---|---|
| Who can edit | Admins with Flow permissions | Developers, with a sandbox and deployment process |
| Reading the logic | Visual canvas, with element labels and descriptions | Source code, with comments and naming |
| Version history | Flow versions, activated one at a time | Source control such as Git |
| Safe change | Save a new version, test, activate | Edit code, run tests, deploy |
| Review | Hard to diff visually | Line-by-line diffs and pull requests |
| Reuse | Subflows | Classes, methods, and interfaces |
Neither column is simply better. Flow is easier to read at a glance for a small automation. A flow with 80 elements, nested loops, and many decisions is harder to read than the equivalent code. Apex is easier to review and reuse, but only people who can write it can maintain it.
Ownership: who will change it?
Ownership means a named person or team is responsible for the automation after launch. Ask these questions before you choose a tool:
- Who gets the request when the business wants a change?
- Can that person make the change without waiting for someone else?
- Who is on call if it fails in production?
- What happens when the original builder leaves?
If your org has admins but no developers, an Apex trigger is a liability. Nobody can fix it, so it is left alone until it breaks. If your org has a strong development team with source control and code review, a large flow may be the weaker option, because it sits outside that process.
Cost you can see and cost you cannot
Some maintenance costs only show up later.
- Platform changes. Salesforce releases three times a year. Flow and Apex both get updates. Apex has API versions, and each class stays on the version it was saved with. Flows also carry an API version.
- Hidden dependencies. Renaming or deleting a field can break a flow or a class. Both tools list field references, but you must check them before changing a field.
- Documentation debt. A flow with no descriptions and a class with no comments are equally hard to take over.
- Test debt. Apex needs test classes that keep passing as the data model changes. A flow has no required tests, so it is easy to change a flow and never check it.
A decision aid for ownership
The diagram is a starting point. Requirements such as bulk volume or complex logic can override it, and later chapters cover those.
Practices that lower maintenance cost in either tool
- Give every flow and class a clear name, such as
Opportunity_AfterSave_SetDiscount, that states the object and the purpose. - Fill in the description of each flow and each element. Comment Apex methods that hold business rules.
- Keep one automation per object and event where you can. Chapter 12 explains why.
- Keep Apex methods short, and move repeated flow logic into subflows.
- Store Apex in source control. Export flows as metadata so they are tracked as well.
- Record the owner in a shared document or in the description field.
Worked example
A company needs to set a field on a case when its priority changes. The admin team has two people. There is no developer on staff, and a contractor handles occasional Apex work.
A record-triggered flow is the better choice here. The logic is one decision and one update. Both admins can read it and change it. If the contractor wrote a trigger, every future edit would need a developer, a sandbox, and a deployment.
Now change one fact. The company has a development team that already maintains 40 Apex classes and runs code review. The same requirement could reasonably go in Apex, because that team already has a process for it. This shows that the right answer depends on the people as much as the requirement.
Exercise
Your org has two admins and no developers. A requirement needs complex string parsing and calls to an external service. Name one risk of building it in Apex, and one risk of forcing it into Flow.
Show answer
Apex risk: no one on the team can maintain or fix it, so the code is left alone until it breaks. Flow risk: the flow becomes large and hard to read, and it may not be able to do the parsing or the callout cleanly. A reasonable compromise is a small Apex action called from a flow, with a developer or contractor named as its owner.