Sub topic 9
Maintenance cost and who owns the automation
What this chapter assumes
This chapter assumes you know the basic Salesforce data model, can find your way around Setup, and have built at least one simple flow. You should also understand basic programming ideas such as variables, loops, and collections. Earlier chapters covered what Apex and Flow are, and where each fits best. This chapter looks at what happens after the first release. Someone has to read, change, and fix the automation for years.
The cost of an automation is not the hours spent building it. Most of the cost comes later, as people change requirements, upgrade the org, leave the team, and debug failures at awkward times. A tool that is fast to build can still be expensive to own.
What "maintenance" covers
Maintenance is every task that keeps an automation correct after it goes live. The main tasks are:
- Changing the logic when the business changes a rule.
- Updating the automation when a field, picklist value, or record type it depends on changes.
- Diagnosing failures, usually from an error email, a user report, or a debug log.
- Keeping the automation compatible with other automations on the same object.
- Moving changes safely from a sandbox (a copy of the org used for development) to production.
- Explaining the automation to a new team member.
Flow and Apex both need all of these. They differ in who can do each task, how visible the logic is, and how much discipline the tool demands.
Who can change it
The most important difference is the size of the group that can safely edit each tool.
| Question | Flow | Apex |
|---|---|---|
| Who can read it? | Admins, analysts, and developers, using Flow Builder's canvas | Developers, and admins with some coding skill |
| Who can change it? | Anyone with the right permissions and Flow Builder experience | Developers working in an IDE or the Developer Console |
| Where is it edited? | Flow Builder in Setup, with a canvas of elements | A code editor, then deployed from a sandbox |
| How are changes reviewed? | Often by opening the flow and checking it visually | Usually by pull request and code review in source control |
| What is the main risk? | A quick edit in production that nobody reviews | Logic that only one or two people can read |
For a team with strong admins and few developers, Flow keeps ownership inside the team that understands the business process. For a team with a development group and a release process, Apex fits the way they already work.
Neither is automatically safer. A flow that any admin can change is also a flow that any admin can break. Code that requires a developer is also code that waits in a queue for that developer.
Readability and visibility
A flow shows its structure. You can see decisions, loops, and record operations laid out on a canvas, and a new admin can follow the path of a record from start to finish. That visual form helps when the flow is small.
Large flows lose this advantage. A flow with dozens of elements, nested loops, and many decision branches becomes hard to follow. Common signs include:
- Elements spread across the canvas with crossing connectors.
- Generic names such as
Decision_1andGet_Records_3. - The same logic copied into several branches.
- Variables whose purpose is unclear.
Code has the opposite profile. A short class is easy to read and diff, but code written without conventions can be hard to follow for anyone outside the development team. Code can be searched, compared line by line, and reviewed in source control. Flow metadata is stored as XML, and a diff of a changed flow is much harder to read than a diff of a changed class.
Naming and documentation
Both tools reward the same habits.
For Flow:
- Give every element a descriptive API name and a description, for example
Get_Open_Opportunitiesinstead ofGet_Records_1. - Write a description on the flow itself that states the object, the trigger, and the purpose.
- Put a version note on each saved version that says what changed and why.
- Split large logic into subflows (flows that other flows call), each with one job.
For Apex:
- Use clear class and method names, and keep each method short.
- Write comments that explain why a decision was made, not what the code does.
- Keep one trigger per object and move the logic into a handler class, so the trigger file stays thin.
- Write tests that document expected behavior, as shown in the earlier testing chapter.
The next example shows the "thin trigger" pattern. It delegates to a handler class so that the logic can be read, tested, and changed in one place. It assumes the Contact_Count__c field exists on Account, as in the earlier trigger example.
trigger ContactTrigger on Contact (after insert) {
ContactTriggerHandler.afterInsert(Trigger.new);
}public with sharing class ContactTriggerHandler {
public static void afterInsert(List<Contact> newContacts) {
Set<Id> accountIds = new Set<Id>();
for (Contact c : newContacts) {
if (c.AccountId != null) {
accountIds.add(c.AccountId);
}
}
if (accountIds.isEmpty()) {
return;
}
List<Account> toUpdate = new List<Account>();
for (AggregateResult ar : [
SELECT AccountId acctId, COUNT(Id) total
FROM Contact
WHERE AccountId IN :accountIds
GROUP BY AccountId
]) {
toUpdate.add(new Account(
Id = (Id) ar.get('acctId'),
Contact_Count__c = (Integer) ar.get('total')
));
}
update toUpdate;
}
}When a rule changes, the developer edits the handler. The trigger file never needs to change unless a new event, such as before update, is added.
The cost of schema change
Both tools depend on the data model. When someone renames a field's API name, deletes a field, or removes a picklist value, automations that use it can break.
Salesforce helps in one direction. It blocks the deletion of a field that is referenced by Apex code or by a flow, so the change fails loudly at the time of the edit. That protection does not cover a picklist value. A flow that tests Stage equals "Negotiation" keeps running after an admin renames the stage, and the condition simply stops matching. The failure is silent, and the symptom is that records no longer get processed.
Apex has the same weakness with string literals. Hard-coded values such as 'Negotiation' or a record type name are not checked at deploy time.
Reduce this risk in either tool with these steps:
- Keep values that might change in custom metadata types or custom labels, and read them from there.
- Use record type developer names, not display labels, when you look up a record type.
- Run the impact check, such as the "Where is this used?" list on a field, before changing a field.
- Keep a test, or a documented manual check, for every status value an automation depends on.
In Apex, a unit test with assertions will fail after the change if the test sets a status and expects an outcome. Flow has built-in flow tests that give a similar safety net, but many orgs have none, so the silent failure often goes unnoticed.
Debugging and failure handling
When something fails, the way you investigate differs.
For Flow:
- A failed record-triggered flow sends an error email to the person who last modified the flow, or to the configured contact, with the failing element and the error text.
- Flow Builder's debug run lets you replay a record through the flow and see the value at each element.
- Fault paths, connectors that run when an element fails, let you handle errors and log them. Without a fault path, an error rolls back the whole transaction and the user sees a generic message.
For Apex:
- Debug logs record the execution, including SOQL queries, DML, and your own
System.debugstatements. - Exceptions can be caught with
tryandcatch, logged to a custom object, and turned into friendly messages. - Unhandled exceptions in asynchronous Apex produce an email to the user who last modified the class, or appear in the Apex Jobs page.
Both tools need a plan for who receives failure notices. If the person named in the flow's last-modified history left the company, nobody reads the emails. Assign a shared mailbox or monitoring queue for automation errors, and check it on a schedule.
Technical debt and sprawl
Technical debt is the future cost created by shortcuts taken today. It builds up differently in each tool.
In Flow, debt usually looks like sprawl. Over several years, an object can collect many record-triggered flows, each added by a different admin for a different request. No single flow is wrong, but together they are hard to reason about, and they run in an order that is hard to predict. A later chapter covers this order and the conflicts it causes.
In Apex, debt usually looks like a growing class. Logic is added to the same handler again and again until one method has hundreds of lines and tests that only cover the happy path. Duplicate logic also appears when two developers solve the same problem separately.
Useful habits for both:
- Consolidate before adding. Check whether an existing flow or handler already covers the object and event.
- Retire dead automation. Deactivate flows that no longer run, and delete unused classes after checking references.
- Review the automation list for each important object once or twice a year.
- Record the business owner for every automation, not only the technical owner.
Platform change and release cadence
Salesforce ships three major releases per year. Both tools stay compatible in nearly all cases, but each needs attention.
- Apex classes carry an API version. Old classes keep working on their old version, but they do not get new language features until someone raises the version and retests.
- Flows also carry an API version, and newer flow features can require a newer version.
- Retired features cause real work. Workflow rules and Process Builder are being replaced by Flow, so orgs that still use them have migration work on their plan.
Because Flow is the platform's focus for declarative automation, new declarative capabilities arrive there first. Apex has a stable, slower-moving language, which suits logic that should not change often.
Ownership models
Teams usually fall into one of three patterns, and the pattern should influence your choice.
- Admin-owned. Admins build and maintain flows. Developers are scarce. Flow is the default, and Apex is used only when a flow cannot do the job. The team needs a review step so that admins do not edit production flows unchecked.
- Developer-owned. A development team runs sandboxes, source control, and a release pipeline. Apex is comfortable here, and flows are still welcome for simple cases if they are deployed through the same pipeline.
- Shared. Admins own the process logic in flows, and developers own the complex pieces as invocable Apex actions. This pattern depends on a clear contract between the two groups, which the invocable method provides.
The shared model works well because each person maintains the part they understand. The cost is coordination. The flow's author must know what the action does, what it expects, and what it returns, so document the action's inputs and outputs.
public with sharing class ApplyDiscountAction {
public class Request {
@InvocableVariable(required=true label='Opportunity Id' description='The opportunity to discount')
public Id opportunityId;
@InvocableVariable(required=true label='Discount Percent' description='A number from 0 to 100')
public Decimal percent;
}
@InvocableMethod(label='Apply Discount' description='Reduces the Amount of each opportunity by the given percent')
public static void apply(List<Request> requests) {
Map<Id, Decimal> percentById = new Map<Id, Decimal>();
for (Request r : requests) {
percentById.put(r.opportunityId, r.percent);
}
List<Opportunity> opps = [
SELECT Id, Amount FROM Opportunity WHERE Id IN :percentById.keySet()
];
for (Opportunity opp : opps) {
if (opp.Amount != null) {
opp.Amount = opp.Amount * (100 - percentById.get(opp.Id)) / 100;
}
}
update opps;
}
}The label and description values appear in Flow Builder, so the admin sees what each input means without opening the class. These small details lower the maintenance cost of the shared model.
Deployment ownership
Who deploys the change is part of ownership. Apex can only reach production through a deployment that runs tests, so a developer or release manager is always involved. Flows can be edited directly in production in many orgs, which is fast but skips review. If your team wants consistent control, deploy both tools through the same pipeline and restrict direct production edits with permissions.
Putting it together
The diagram shows how ownership questions lead to a maintenance plan.
Use these checks before you commit to a build:
- Name a business owner and a technical owner.
- Name a shared mailbox for failure notices.
- Decide how changes reach production and who approves them.
- Write down which other automations touch the same object and event.
- Set a date to review the automation.
Common mistakes
- Treating build time as the full cost of an automation.
- Leaving default element names such as
Decision_1in a flow that others must read. - Sending error emails to one person's address.
- Editing a production flow directly and skipping review.
- Putting all logic for an object into one large trigger or one large flow.
- Hard-coding values that the business changes often.
- Never retiring automations that no longer have a purpose.
Exercise
Your team has two admins and no developers. A requirement needs a record-triggered action that updates a field when an opportunity reaches a certain stage, and the rule changes about twice a year. Which tool would you choose, and which three practices would you apply to keep it maintainable?
Show answer
Choose Flow, because the admins who own the process can read and change it. Practices: give every element a descriptive name and add descriptions to the flow and each version; store the stage name in a custom label or custom metadata instead of hard-coding it; and name an owner and a shared mailbox for error emails. Also add a flow test, and review the object's other flows for conflicts before activating.
Exercise
A flow tests whether an Opportunity's StageName equals "Negotiation". An admin renames that picklist value to "Contract Negotiation", and Salesforce lets the change through. What happens to the flow, and how would you have prevented it?
Show answer
The flow keeps running but the condition never matches, so affected records are silently skipped. Salesforce blocks deleting a referenced field but does not check picklist values inside flow conditions. Prevention: keep stage values in custom metadata or labels, check where the value is used before renaming it, and keep a flow test or Apex test that asserts the outcome for each stage.
Exercise
Why can the "shared" ownership model, with admins building flows and developers writing invocable Apex actions, lower maintenance cost? What does it require to work?
Show answer
Each group maintains the part it understands: admins own the process steps, and developers own the complex logic. It requires a clear contract between them, meaning a documented action with labeled and described inputs and outputs, plus agreement on who fixes failures in each part.