Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
Full Function entry
How-to guide

Pick the right function surface for your task

Function choice is rarely binary. Most non-trivial logic uses a mix of formula functions for inline computation, Apex methods for orchestration, and SOQL aggregates for summarization. Walk the decision tree.

By Dipojjal Chakrabarti · Founder & Editor, Salesforce DictionaryLast updated May 21, 2026

Function choice is rarely binary. Most non-trivial logic uses a mix of formula functions for inline computation, Apex methods for orchestration, and SOQL aggregates for summarization. Walk the decision tree.

  1. Identify the trigger

    Is the logic running on record load (formula), on save (validation rule, flow, Apex trigger), inside a query (SOQL function), or on demand from a UI (Apex controller, LWC method)?

  2. Pick the surface

    Inline read-only math: formula function. DML side effects: flow or Apex. Cross-record summary: SOQL aggregate or rollup-summary field. External call: Apex with a Named Credential or a flow with an HTTP Callout action.

  3. Write the smallest version first

    Build the minimum function that produces the right output for one record. Skip premature abstraction.

  4. Test with edge cases

    Null inputs, max-length text, currency conversion, multi-currency rounding. Each surface has its own failure modes; cover the ones that fit.

  5. Refactor once duplication appears

    Wait for the third copy before factoring out. Two copies is coincidence; three is a pattern.

Gotchas
  • Formula functions look harmless but they re-execute on every record view. Heavy VLOOKUP usage on a frequently-viewed object can quietly degrade list-view performance.
  • Apex method signatures are part of the org's API surface once a managed package ships them. Renaming or removing a public method breaks every dependent consumer.
  • SOQL aggregate queries return AggregateResult, not the source sObject. The Apex code calling the aggregate must handle the typeless map keys (get('expr0')) or use FIELDS() with proper aliases.
  • Salesforce Functions is retired. Any documentation, blog post, or training course referencing the product is out of date. Migrate to Apex or Heroku.

See the full Function entry

Function includes the definition, worked example, deep dive, related terms, and a quiz.