Sub topic 3
Maintenance Cost and Who Owns the Automation
Assume you know Salesforce objects, fields, records, Setup, simple Flow design, and basic programming concepts such as loops and collections.
Maintenance cost and ownership
Automation has two costs: building it and changing it later. Flow is usually easier for an administrator to inspect and modify. Apex needs a developer who understands classes, tests, deployment, and governor limits.
Ownership should be explicit. The team should document the automation’s purpose, entry conditions, related flows or triggers, and test coverage.
| Choice | Typical owner | Maintenance concern |
|---|---|---|
| Flow | Administrator or analyst | Many flows can become difficult to trace |
| Apex | Developer | Code changes require tests and deployment |
| Flow plus Apex | Shared team | The boundary between tools must be documented |
A small field update may fit Flow. Complex calculations, reusable logic, or integrations may justify Apex even when Flow could technically perform the task.
A practical framework for choosing
Ask these questions in order:
- Can a clear Flow handle the requirement with readable branches and no repeated database work?
- Does the requirement need complex data structures, recursion-like processing, or reusable code?
- Will many records be processed in one transaction?
- Can the team test and deploy the chosen solution safely?
- Who will own future changes?
Choose the simplest tool that meets the requirement and remains understandable to its owner.
Using both: calling Apex from Flow
A Flow can call an Apex invocable method as an Action. This works well when Flow handles entry conditions and user-facing decisions while Apex handles complex processing.
The method accepts a list because one Flow interview can run as part of bulk processing. The implementation must still use bulk-safe queries and updates.
public with sharing class ApplyDiscountAction {
public class Request {
@InvocableVariable(required=true)
public Id opportunityId;
@InvocableVariable(required=true)
public Decimal percent;
}
@InvocableMethod(label='Apply Discount')
public static void apply(List<Request> requests) {
Map<Id, Decimal> discounts = new Map<Id, Decimal>();
for (Request request : requests) {
discounts.put(request.opportunityId, request.percent);
}
List<Opportunity> opportunities = [
SELECT Id, Amount
FROM Opportunity
WHERE Id IN :discounts.keySet()
];
for (Opportunity opportunity : opportunities) {
if (opportunity.Amount != null) {
Decimal percent = discounts.get(opportunity.Id);
opportunity.Amount *= (100 - percent) / 100;
}
}
update opportunities;
}
}Avoiding conflicts between automations
Several flows, triggers, and Apex actions on the same object can update the same field. This can cause repeated saves, unexpected final values, or order-dependent behavior.
Use one clear owner for each business rule. Review all automation on the object before adding another component. Give each component a narrow responsibility, and test the complete transaction rather than testing only one automation.
Exercise
A requirement needs simple entry criteria and a complex, reusable calculation. Which design is usually appropriate?
Show answer
Use Flow for the entry criteria and call an Apex invocable action for the calculation.