Skip to content

DML Lib

The DML Lib provides functional constructs for DMLs in Apex.

API version

License

GitHub Repo starsGitHub ReleaseCodecov

Why DML Lib?

  • Mock DMLs in Apex Tests - Built-in mocking support lets you test your code without database operations, making tests faster and more isolated.
  • Comprehensive Results - Get detailed operation results including success/failure status, record IDs, and error information for each DML operation.
  • Security Controls - Full support for User/System mode and With/Without Sharing, plus field-level security stripping.
  • Relationship Handling - Automatically resolve parent-child relationships across inserts. No need to manually assign IDs after parent inserts.
  • Immediate Operations - Execute single DML operations immediately and get results without needing to call commitWork().

Quick Start

apex
Account account = new Account(Name = 'Acme Corp');
Contact contact = new Contact(LastName = 'Smith');

new DML()
    .toInsert(account)
    .toInsert(DML.Record(contact).withRelationship(Contact.AccountId, account))
    .commitWork();

// contact.AccountId is automatically set to account.Id

Documentation

Installation

Released under the MIT License.