Wednesday 15 May 2013


Persisting Database Records

Changes to database records in Force.com are saved using Data Manipulation Language
(DML) operations. DML operations allow you to modify records one at a time, or more
efficiently in batches of multiple records.The five major DML operation types are listed
next. Each is discussed in more detail later in this subsection.

  •  Insert: Creates new records.
  •  Update: Updates the values in existing records, identified by Force.com unique identifier (Id) field or a custom field designated as an external identifier.
  •  Upsert: If records with the same unique identifier or external identifier exist, this updates   their values. Otherwise, it inserts them.
  • Delete: Moves records into the Recycle Bin.
  •  Undelete: Restores records from the Recycle Bin.

DML operations can be included in Apex code in one of two ways: DML statements and
database methods. Beyond the syntax, they differ in how errors are handled. If any one
record in a DML statement fails, all records fail and are rolled back. Database methods
allow for partial success.

Note

Usage of DML in Apex is subject to governor limits. For example, you are limited to a total of
150 DML operations. The cumulative maximum number of records modified by all DML operations
is 10,000.

No comments:

Post a Comment