Newer Version Available

This content describes an older version of this product. View Latest

Expressions

An expression is a construct made up of variables, operators, and method invocations that evaluates to a single value.

In Apex, an expression is always one of the following types:

  • A literal expression. For example:
  • A new sObject, Apex object, list, set, or map. For example:
  • Any value that can act as the left-hand of an assignment operator (L-values), including variables, one-dimensional list positions, and most sObject or Apex object field references. For example:
  • Any sObject field reference that is not an L-value, including:
    • The ID of an sObject in a list (see Lists)
    • A set of child records associated with an sObject (for example, the set of contacts associated with a particular account). This type of expression yields a query result, much like SOQL and SOSL queries.
  • A SOQL or SOSL query surrounded by square brackets, allowing for on-the-fly evaluation in Apex. For example:

    For information, see SOQL and SOSL Queries.

  • A static or instance method invocation. For example: