---
schema_version: "1"
id: 1e058a2405931daf566f570f78098369e72baa5914d455335f1d002487cb6db6
title: Expanding sObject and List Expressions
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexcode/langCon_apex_expressions_extending_SObjects.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_expressions_extending_SObjects.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: c0ccc7630f97a493bb87fd047315c9456e8f8273f81cfb4e8b66a7af42e9c131
---
# Expanding sObject and List Expressions

As in Java, sObject and list expressions can be expanded with method references and list expressions, respectively, to form new expressions.

In the following example, a new variable containing the length of the new account name is assigned to acctNameLength.

Integer acctNameLength = new Account\[\]{new Account(Name='Acme')}\[0\].Name.length();

In the above, new Account\[\] generates a list.

The list is populated with one element by the new statement {new Account(name='Acme')}.

Item 0, the first item in the list, is then accessed by the next part of the string \[0\].

The name of the sObject in the list is accessed, followed by the method returning the length name.length().

In the following example, a name that has been shifted to lower case is returned. The SOQL statement returns a list of which the first element (at index 0) is accessed through \[0\]. Next, the Name field is accessed and converted to lowercase with this expression .Name.toLowerCase().

String nameChange = \[SELECT Name FROM Account WITH USER\_MODE\]\[0\].Name.toLowerCase();