Choosing the right operator means matching the data type, the context (formula vs SOQL vs Flow), and the semantics you actually need. Walk through the decision systematically.
- Identify the context
Formula field, validation rule, workflow rule, Flow condition, SOQL query, report filter, or SAQL? Each context has its own operator vocabulary; pick the right one before writing the expression.
- Identify the data type
Number, text, date, datetime, picklist, multi-select picklist, ID, boolean? Operators that work for numbers (<, >) often do not work for text. Multi-select picklists need INCLUDES, not =.
- Pick the operator that matches semantics
Are you comparing equality, ordering, set membership, pattern, or blankness? Equality uses =, ordering uses < or >, set membership uses IN, pattern uses LIKE, blankness uses ISBLANK.
- Wrap with parentheses for precedence
Mixed AND/OR conditions are ambiguous without parentheses. Always group explicitly. AND(OR(a, b), c) reads correctly; a OR b AND c is fragile.
- Test against edge cases
Null values, empty strings, dates at month boundaries, multi-select picklists with no selections, and negative numbers all expose operator bugs. Build test scenarios that hit each.
Compare two values for exact match. Default operator for most string and ID comparisons.
Compare numeric or date values. Does not work for text in most contexts.
Match a substring or wildcard pattern. LIKE in SOQL; CONTAINS in formulas.
Check if a value is in a list. IN for single-value fields; INCLUDES for multi-select picklists.
Combine conditions. Use parentheses to make precedence explicit.
Test for empty values. ISBLANK is the safer choice for text fields.
- Equals vs assignment is a classic bug. In formulas and SOQL, = is comparison. In Apex, = is assignment and == is comparison. Mixing them up causes silent errors.
- Multi-select picklists do not compare with =. Use INCLUDES and EXCLUDES, even though Salesforce sometimes lets = silently pass and return nothing.
- LIKE in SOQL is case-insensitive but column collation can change behavior. Test pattern queries in the actual context the production code uses.
- Operator precedence in formulas is not the same as in SQL or Apex. AND binds tighter than OR in formulas; in some contexts (Flow conditions), the engine evaluates conditions in source order. When in doubt, parenthesize.