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) and can navigate Setup and the Object Manager. Reading simple Apex is helpful but not required.
What "clicks before code" means
"Clicks before code" is a design principle. When a requirement can be met by configuring Salesforce in Setup, you configure it. You write Apex only when configuration cannot do the job, or cannot do it safely at your data volume.
The principle does not say code is bad. It says every extra layer of complexity has a cost, and you should pay that cost only when it buys something.
Why the simplest tool wins
Declarative tools (validation rules, formula fields, roll-up summary fields, Flow, approval processes) have properties that code lacks by default:
- Lower build and change cost. An admin can read and edit a flow. Changing Apex means a developer, a sandbox, tests, and a deployment.
- Platform-managed behavior. Declarative features handle bulk processing, and in many cases sharing and field-level details, for you.
- Easier maintenance. Salesforce upgrades declarative features. Apex needs 75% test coverage to deploy and its own maintenance when the data model changes.
- Better transparency. A flow is a visual diagram. Someone new to the org can see what happens when an Opportunity closes.
Code has its own strengths: precise control, complex logic, high volumes, unit tests, and version control. The task is to match the tool to the problem, starting from the cheapest option that fits.
The escalation ladder
Work down this list and stop at the first tool that meets the requirement. The order follows the decision checklist the rest of the tutorial expands on.
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.A worked comparison
Take this requirement: when an Account is saved with annual revenue of at least 1,000,000, set its Rating to "Hot".
The code answer
trigger AccountTrigger on Account (before insert, before update) {
for (Account acc : Trigger.new) {
if (acc.AnnualRevenue != null && acc.AnnualRevenue >= 1000000) {
acc.Rating = 'Hot';
}
}
}This trigger is correct and bulk-safe. It has no query and no DML statement, because a before trigger changes the records in memory before they are saved. Deploying it still requires a test class, a deployment, and a developer for every future change to the threshold.
The click answer
A before-save record-triggered flow on Account does the same thing:
- Create a record-triggered flow that runs when a record is created or updated.
- Add a condition: Annual Revenue is greater than or equal to 1000000.
- Use an Assignment element to set
$Record.RatingtoHot.
No test class is required to deploy the flow. An admin can change the threshold in minutes. Before-save flows are also fast, because like the trigger they update the record without an extra database write.
This is why the example is a good tool-comparison case. Both tools produce identical results, so the simpler one is the better choice.
When code is justified
Clicks before code does not mean never code. Move up the ladder when you can name a concrete reason. Common reasons:
- Logic Flow handles poorly. Complex algorithms, heavy string or collection manipulation, recursion, or logic that is hard to follow as a diagram.
- Volume. Very large data sets can exceed what a flow comfortably processes in one transaction.
- Integration needs. Custom callouts, complex parsing, or work that needs precise error handling.
- Reuse and testability. Logic shared across many entry points, or logic that needs thorough automated unit tests.
- Capabilities Flow lacks. Some operations are only available in Apex.
Asynchronous work is one such case. A Queueable class runs in its own transaction with its own governor limits:
public class RecalculateRatingJob implements Queueable {
private List<Id> accountIds;
public RecalculateRatingJob(List<Id> accountIds) {
this.accountIds = accountIds;
}
public void execute(QueueableContext context) {
List<Account> accounts = [SELECT Id, AnnualRevenue FROM Account WHERE Id IN :accountIds];
for (Account acc : accounts) {
acc.Rating = (acc.AnnualRevenue != null && acc.AnnualRevenue >= 1000000) ? 'Hot' : 'Warm';
}
update accounts;
}
}
// Enqueue from Apex, for example inside a trigger handler:
// System.enqueueJob(new RecalculateRatingJob(accountIdList));The job uses one query and one DML statement for the whole list, so it stays within limits however many Accounts it receives. Later chapters cover governor limits and asynchronous Apex in detail.
Common errors when applying the principle
Treating it as a rule against code
Forcing a flow to do work it handles badly produces a sprawling diagram that nobody can maintain. A 60-element flow with nested loops is harder to support than 40 lines of tested Apex. When you hit this point, move up the ladder.
Skipping the simplest rung
The opposite mistake is building a flow where a formula field is enough. If a value can be computed from other fields on the same record, a formula field needs no automation at all and cannot get out of date.
Choosing by habit
Teams tend to reach for the tool they know best. A developer writes a trigger for everything. An admin builds flows for everything. Check each requirement against the ladder instead.
Ignoring what already exists
The simplest tool for a requirement may still conflict with automation already on the object. Before adding anything, check what Flows, triggers and legacy rules already run on it. Later chapters on order of execution and coexistence cover this.
Deciding on today's volume only
A flow that works for ten records a day may fail during a data load of 200,000. Ask about peak volume and integrations before you commit to a tool.
A short checklist before you build
- State the requirement in one sentence, including what triggers it and what must happen.
- Walk the ladder from the top and write down why each skipped rung does not fit.
- Check existing automation on the same object.
- Estimate peak volume, including data loads and integrations.
- Record the reason if you choose code, so the next person understands the decision.
Summary
Start with the simplest tool that meets the requirement, and move to a more complex one only for a stated reason. For a field set on the saved record, a before-save flow and a before trigger give the same result, and the flow is cheaper to build and change. For logic, volume, or capabilities beyond Flow, Apex is the right choice, and slow work belongs in asynchronous Apex.
Exercise
A requirement says "When an Opportunity is saved, set the Description field to the text 'Large deal' if Amount is over 500,000." Which rung of the ladder do you try first, and which two Salesforce tools could meet the requirement? Which would you pick and why?
Show answer
Try the record-triggered flow rung first, since the work happens when a record is saved and a validation rule, formula field or roll-up summary field cannot write a value into a normal field. A before-save record-triggered flow or a before insert/update Apex trigger could both do it. Pick the before-save flow. It changes the same record without an extra DML statement, needs no test class, and an admin can adjust the 500,000 threshold. Use the trigger only if a stated reason, such as logic Flow cannot express, rules the flow out.
Exercise
A team built a flow with many nested loops and callouts to process 300,000 records from a nightly integration. It keeps failing. Does this show that clicks before code is wrong? What should the team do?
Show answer
No. The principle means starting with the simplest tool that works, and this flow does not work at this volume and complexity. The team should move up the ladder and implement the logic in Apex, using asynchronous Apex such as Batch or Queueable for the high volume, and record why Flow was rejected.