Skip to content

Make DML Operation Order Configurable #59

Description

@devHamid93

Is your feature request related to a problem? Please describe.

The execution order of DML operations is currently hardcoded as follows:

  1. Insert
  2. Update
  3. Merge
  4. Delete
  5. Undelete
  6. Publish

This fixed order does not work for every use case. In some scenarios, developers need certain operations to run earlier or later—for example, executing deletes before inserts or publishing events before other operations are processed.

At the moment, developers cannot control this order without modifying or working around the library's internal behavior.

Describe the solution you'd like

The DML operation order should be configurable by the developer.

The existing order should remain the default to preserve backward compatibility. Developers should optionally be able to provide a custom ordered list of operations.

For example:

DML dml = new DML();

dml.setOperationOrder(new List<DML.OperationType>{
    DML.OperationType.DELETE,
    DML.OperationType.INSERT,
    DML.OperationType.UPDATE,
    DML.OperationType.MERGE,
    DML.OperationType.UNDELETE,
    DML.OperationType.PUBLISH
});

dml.execute();

Alternatively, the configuration could be provided through a builder or global configuration:

DML dml = DML.builder()
    .withOperationOrder(new List<DML.OperationType>{
        DML.OperationType.DELETE,
        DML.OperationType.UPDATE,
        DML.OperationType.INSERT
    })
    .build();

Operations that are not explicitly included could either:

  • be appended using the default order, or
  • cause a validation error.

The preferred behavior should be clearly documented.

Additional context

The current default order should remain unchanged:

insert → update → merge → delete → undelete → publish

This feature would only introduce an optional override.

It would provide more flexibility for complex transactions, custom dependency handling, integrations, and use cases where the required execution sequence is not based solely on SObject or record dependencies.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions