-
Notifications
You must be signed in to change notification settings - Fork 0
The Dml Class
The Dml class is designed to streamline and enhance DML operations within Salesforce.
It encapsulates standard DML keywords and Database methods, providing a simplified interface for CRUD operations. This class enables developers to easily mock DML operations, improving unit testing and reducing complexity.
Dml objects cannot be directly constructed via the new keyword. Instead, access the class and its methods via the DatabaseLayer.Dml static property:
DatabaseLayer.Dml.doInsert(record);The DatabaseLayer class is responsible for instantiating database objects of the correct type at runtime. In @IsTest context, developers can call DatabaseLayer.useMocks(), and an instance of the MockDml class will be returned instead:
DatabaseLayer.useMocks();
Assert.isInstanceOfType(DatabaseLayer.Dml, MockDml.class, 'Not a mock');The Dml class contains methods which mirror the functionality of DML methods in the standard Database class, including its numerous method overloads.
Since DML keywords (like insert, update, and delete) are reserved, the Dml class's methods are prefixed with the "do" predicate. For example, doInsert, doUpdate, and doDelete.
DatabaseLayer.Dml.doUpdate(account, false, System.AccessLevel.USER_MODE);Converts a lead into an account and contact, as well as (optionally) an opportunity.
See Database.convertLead for more information.
Deletes an existing sObject record, such as an individual account or contact, from your organization's data.
See Database.delete for more information.
Initiates requests to delete the external data that corresponds to the specified external object records. The request is executed asynchronously, as a background operation, and is sent to the external system that's defined by the external object's associated external data source. Allows referencing a callback class whose processDelete method is called for each record after deletion.
See Database.deleteAsync for more information.
Initiates requests to delete the external data that corresponds to the specified external object records. The requests are executed synchronously and are sent to the external systems that are defined by the external objects' associated external data sources. If the Apex transaction contains pending changes, the synchronous operations can't be completed and throw exceptions.
See Database.deleteImmediate for more information.
Adds an sObject, such as an individual account or contact, to your organization's data.
See Database.insert for more information.
Initiates requests to add external object data to the relevant external systems. The requests are executed asynchronously, as background operations, and are sent to the external systems that are defined by the external objects' associated external data sources. Allows referencing a callback class whose processSave method is called for each record after the remote operations are completed.
See Database.insertAsync for more information.
Initiates requests to add external object data to the relevant external systems. The requests are executed synchronously and are sent to the external systems that are defined by the external objects' associated external data sources. If the Apex transaction contains pending changes, the synchronous operations can't be completed and throw exceptions.
See Database.insertImmediate for more information.
Publishes the given list of platform events.
See EventBus.publish for the full list of method signatures.
Restores an existing sObject record, such as an individual account or contact, from your organization's Recycle Bin.
See Database.undelete for the full list of method signatures.
Modifies an existing sObject record, such as an individual account or contact, in your organization's data.
See Database.update for the full list of method signatures.
Initiates requests to update external object data on the relevant external systems. The requests are executed asynchronously, as background operations, and are sent to the external systems that are defined by the external objects' associated external data sources. Allows referencing a callback class whose processSave method is called for each record after the remote operations are completed.
See Database.updateAsync for more information.
Initiates requests to update external object data on the relevant external systems. The requests are executed synchronously and are sent to the external systems that are defined by the external objects' associated external data sources. If the Apex transaction contains pending changes, the synchronous operations can't be completed and throw exceptions.
See Database.updateImmediate for more information.
Creates a new sObject record or updates an existing sObject record within a single statement, using a specified field to determine the presence of existing objects, or the ID field if no field is specified.
See Database.upsert for more information.
Permanently deletes the specified records from the Recycle Bin.
See Database.emptyRecycleBin for more information.
Releases a given savepoint. All savepoints that are subsequent to the given one are also released.
See Database.releaseSavepoint for more information.
See Database.rollback for more information.
Returns a savepoint variable that can be stored as a local variable, then used with the rollback method to restore the database to that point.
See Database.setSavepoint for more information.
- Generating Test Records
- Dml
- Soql
- Cmdt
- Plugins
- DatabaseLayer
- Dml
- MockDml
- MockRecord
- Cmdt
- MockCmdt
- MockSoql
-
Soql
- Soql.AggregateResult
- Soql.Aggregation
- Soql.Binder
- Soql.Builder
- Soql.Condition
- Soql.ConditionalLogic
- Soql.Criteria
- Soql.Cursor
- Soql.Function
- Soql.InnerQuery
- Soql.InvalidParameterValueException
- Soql.LogicType
- Soql.NullOrder
- Soql.Operation
- Soql.Operator
- Soql.ParentField
- Soql.PreAndPostProcessor
- Soql.QueryLocator
- Soql.Request
- Soql.Scope
- Soql.Selectable
- Soql.SortDirection
- Soql.SortOrder
- Soql.Subquery
- Soql.TypeOf
- Soql.Usage
- Soql.WhenClause