Working with Data in Apex
You can add and interact with data in the Lightning Platform persistence layer. The sObject data type is the main data type that holds data objects. You’ll use Data Manipulation Language (DML) to work with data, and use query languages to retrieve data, such as the (), among other things.
-
In this developer guide, the term sObject, when used as a placeholder value, refers to any object that can be stored in the Lightning platform database.
-
Apex enables you to insert, update, delete or restore data in the database. DML operations allow you to modify records one at a time or in batches.
-
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.
-
SOQL
forloops iterate over all of the sObject records returned by a SOQL query. -
You can manage sObjects in lists, sets, and maps.
-
Apex Security and Sharing Model
The Apex security model includes record-level, field-level, and object-level security mechanisms. You can control record-level security modes by using the
with sharing,without sharing, andinherited sharingkeywords on classes. Apex runs in user mode by default, which means that user permissions on objects and field-level security are respected. A user cannot run code that tries to access fields or objects that are hidden from the user. Other security mechanisms include theSecurity.stripInaccessible()method, and Field and SObject describe methods. -
Custom settings are similar to custom objects. Application developers can create custom sets of data and associate custom data for an organization, profile, or specific user. All custom settings data is exposed in the application cache, which enables efficient access without the cost of repeated queries to the database. Formula fields, validation rules, flows, Apex, and SOAP API can then use this data.