Sub topic 2
Clicks before code: start with the simplest tool that works
This chapter assumes you know the Salesforce data model (objects, fields, records, relationships), can navigate Setup and the Object Manager, and can read simple Apex. You do not need to write Apex yourself.
What the principle says
"Clicks before code" means you solve a requirement with the simplest tool that works. Declarative tools are the ones you configure with clicks in Setup. These include validation rules, formula fields, roll-up summary fields, and Flow. Apex is code. Move to code only when a declarative tool cannot meet the requirement.
The reasons are practical:
- Declarative features are easier for admins to read and change.
- Salesforce maintains them and upgrades them with each release.
- They need no test classes or deployment of code.
- Code has more ways to fail, such as governor limit errors and bugs in logic.
The principle is not "never write code". Apex is the right tool for complex logic, very large volumes, and work that Flow cannot do. The principle only sets the order in which you consider your options.
The ladder
Work down this list and stop at the first tool that fits.
1. Can a validation rule, formula field or roll-up summary field solve it? Use that.
2. Does it run when a record is created or updated? Try a record-triggered flow (before-save to change the same record, after-save for related records or actions).
3. Does a user need guided steps? Use a screen flow.
4. Does it run on a schedule? Use a scheduled flow, or scheduled Apex for very large volumes.
5. Does it need formal sign-off? Use an approval process, or Flow Orchestrator for multi-step work across users.
6. Does it need complex logic, very large volumes, or something Flow cannot do? Use Apex, and move slow work to asynchronous Apex.Later chapters expand each step. For now, notice that the list runs from the least complex tool to the most complex.
A worked comparison
Suppose the requirement is: "When an Account is saved with annual revenue of 1,000,000 or more, set its Rating to Hot."
The Apex version is a before trigger:
trigger AccountTrigger on Account (before insert, before update) {
for (Account acc : Trigger.new) {
if (acc.AnnualRevenue != null && acc.AnnualRevenue >= 1000000) {
acc.Rating = 'Hot';
}
}
}This works and is bulk safe. A before-save record-triggered flow does the same job with a decision element and an assignment, and no code. Under clicks before code, the flow is the better first choice. The trigger needs a test class, a deployment, and a developer to maintain it.
When code is justified
Code earns its place when one of these holds:
- The logic is too complex to express clearly in Flow.
- Volumes are high enough that Flow performs poorly or hits limits.
- You need an API or capability Flow does not expose.
- The team already has a tested Apex framework on the object.
Common errors
- Treating the principle as a rule against code, and building fragile flow logic where a short Apex class would be clearer.
- Choosing Apex out of habit, then leaving admins unable to change a simple rule.
- Adding a new tool on an object without checking which automations already exist there. Chapter later in this tutorial covers this conflict.
Exercise
A requirement says that when an Opportunity moves to Closed Won, the Owner's manager must get a task created. Which step on the ladder do you try first, and what would justify moving to Apex instead?
Show answer
Try a record-triggered flow first (step 2). Because it creates a related record (the task), an after-save flow fits. Move to Apex only if the logic is too complex for Flow, the volume causes Flow to hit limits, or Flow cannot perform a needed action.