---
schema_version: "1"
id: 60fccfbb012f0fd5f8ec1df3fc8cfbebd62aa345eb31e62716c85eb6439e9fdb
title: Expressions
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexcode/langCon_apex_expressions_understanding.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_expressions_understanding.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 9204d29d2b8fa82c4d70bfe790bb03ec361ebe6e8be7a0dae0764ec272b625dd
description: An expression is a construct made up of variables, operators, and method invocations that evaluates to a single value.
---
# 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:
    
    1 + 1
- A new sObject, Apex object, list, set, or map. For example:
    
    new Account(<field\_initializers>)
    new Integer\[<n>\]
    new Account\[\]{<elements>}
    new List<Account>()
    new Set<String\>{}
    new Map<String, Integer\>()
    new myRenamingClass(string oldName, string newName)
- 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:
    
    Integer i
    myList\[3\]
    myContact.name
    myRenamingClass.oldName
- Any sObject field reference that is not an L-value, including:
    - The ID of an sObject in a list (see [Lists](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_collections_lists.htm "A list is an ordered collection of elements that are distinguished by their indices. List elements can be of any data type—primitive types, collections, sObjects, user-defined types, and built-in Apex types."))
    - 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:
    
    Account\[\] aa = \[SELECT Id, Name FROM Account WHERE Name ='Acme' WITH USER\_MODE\];
    Integer i = \[SELECT COUNT() FROM Contact WHERE LastName ='Weissman' WITH USER\_MODE\];
    List<List<SObject>> searchList = \[FIND 'map\*' IN ALL FIELDS RETURNING Account (Id, Name), Contact, Opportunity, Lead\];
    
    For information, see [SOQL and SOSL Queries](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL.htm "You can evaluate Salesforce Object Query Language (SOQL) or Salesforce Object Search Language (SOSL) statements on-the-fly in Apex by surrounding the statement in square brackets.").
- A static or instance method invocation. For example:
    
    Assert.isTrue(true)
    myRenamingClass.replaceNames()
    changePoint(new Point(x, y))