Section 2 · Developer Fundamentals · 27% of exam
2.2 Declarative or Programmatic? Choosing the Right
Exam objective
Given a business scenario, compare declarative and programmatic capabilities and choose a maintainable design using formulas, roll-up summaries, Flow, or Apex.
Customization
Start with the requirement, not the tool
A good Salesforce design starts by translating the request into observable outcomes. Identify the event that starts the work, the records and fields involved, the decision rules, who needs to interact with it, how many records can be processed, and what must happen if a step fails. Then compare platform capabilities.
Declarative features are usually preferable when they directly express the requirement and remain understandable to the admins and developers who will maintain the org. A formula calculates a value from other values. A validation rule prevents a save when a condition is false. A record-triggered Flow automates record changes and related actions. A screen Flow guides a user through a process. Approval capabilities route a record for review. These tools can be tested and governed, but they still need clear entry criteria, fault handling, and access design.
Programmatic customization is appropriate when a requirement needs complex algorithms, reusable services, transaction control, custom interface behavior, operations not supported by declarative elements, or efficient bulk data handling. Apex can also encapsulate logic called from Flow. The chosen design should be no more complex than necessary while meeting security, scale, and behavior requirements.
Compare the main declarative choices
Use a formula when the value is derived and can be calculated at read time. A formula field is not an independently editable copy of the value. For example, a “days until renewal” display may be a formula using a date field and the current date. If another automation needs a stored snapshot for audit or downstream processing, a formula may not satisfy that requirement.
A roll-up summary calculates an aggregate over related child records on a master record, such as the sum of approved expenses. Standard roll-up summaries require a master-detail relationship and support specific aggregate calculations and filters. If records use a lookup, a standard roll-up may not be available; the solution could require a relationship redesign, Flow, or code, depending on limits and latency. The exam asks candidates to recognize both the capability and its relationship constraints.
A validation rule is suited to a save-time condition such as requiring a reason when a case moves to a particular status. It should prevent invalid state while giving users an actionable message. It does not replace an automation that needs to create or update other records. A record-triggered Flow can handle supported record changes and orchestration. Before-save flows are useful for updating fields on the triggering record; after-save flows can take actions that depend on a saved record, including related record work.
Use a decision sequence
- Can a formula, validation rule, or native relationship behavior fully meet the requirement? Prefer that when its timing and stored-value behavior fit. 2. Does the process need user interaction or multi-step orchestration? Consider a screen Flow or another supported Flow type. 3. Does the logic require reusable code, complex computation, or a specific custom UI? Use Apex or a component for that part. 4. Will the behavior be invoked for many records? Confirm collection handling, limits, and fault behavior. 5. Who maintains it, and what permissions apply at runtime? Choose the simplest option the team can safely support.
Consider a request to reject an order when a required compliance field is blank, calculate the total of child payments, and notify the owner when the order is approved. A validation rule may enforce the required field, a roll-up summary may calculate the total if the relationship qualifies, and Flow may send the notification. Apex is not automatically necessary. If the same approval calculation involves a sophisticated algorithm or must be reused by several entry points, a tested Apex service could be called from Flow.
Overlapping Flow and Apex automations can update the same record multiple times. Document which layer owns each decision, and trace the full save cycle before adding a second automation.
Extra concept: testability is part of the design decision
Declarative does not mean “no testing,” and code does not mean “more reliable.” A maintainable solution exposes clear inputs and outcomes, has deterministic decision rules, and can be tested with normal, boundary, and failure data. Include testing and observability when comparing design options.
Key takeaways
- Pick the tool from timing, user interaction, complexity, reuse, record volume, and maintenance needs.
- Formulas calculate values, validation rules block invalid saves, roll-ups aggregate supported master-detail children, and Flow orchestrates declarative work.
- Use Apex for justified custom behavior and integrate it with Flow through a clear, bulk-safe boundary. Official references:
- Salesforce Certified Platform Developer Exam Guide: https://help.salesforce.com/s/articleView?id=005298965&language=en_US&type=1
- Flow Builder: https://help.salesforce.com/s/articleView?id=sf.flow.htm&type=5
- Formula fields: https://help.salesforce.com/s/articleView?id=sf.customize_formulas.htm&type=5
- Roll-up summary fields: https://help.salesforce.com/s/articleView?id=sf.fields_about_roll_up_summary_fields.htm&type=5
- Apex Developer Guide: https://developer.salesforce.com/docs/platform/apex/guide
