- Light wrapper for Salesforce DML Operations, that logs to Nebula Logger.
- Requires Nebula Logger.
| DML Operation | DmlOps Method |
|---|---|
| Insert | DmlOps.create() |
| Update | DmlOps.modify() |
| Upsert | DmlOps.upsrt() |
| Delete | DmlOps.remove() // TODO |
All methods accept the below parameters
| Parameter | Type | Required |
|---|---|---|
| records | List | Yes |
| options | DmlOps.Options | No |
| Property | Type | Description |
|---|---|---|
allOrNone |
Boolean |
Same as the standard Salesforce Database class allOrNone parameter. Defaults to false (Note: that is the opposite of the standard behaviour) |
logSuccess |
Boolean |
Whether to log successes or not. Defaults to false |
loggingScenario |
String |
Sets the Nebula Logging Scenario. Defaults to DML: {Object} |
List<Account> accounts = new List<Account>{new Account()};
DmlOps.create(accounts);
List<Account> accounts = [SELECT Id FROM Account LIMIT 1];
accounts[0].Name = null;
DmlOps.modify(accounts);
Results are always available to the caller, for further handling e.g.
List<Account> accounts = new List<Account>{new Account()};
List<Database.SaveResults> results = DmlOps.create(accounts);
List<Account> accounts = new List<Account>{new Account()};
DmlOps.Options options = new DmlOps.Options();
options.loggingScenario = 'Test Scenario';
DmlOps.create(accounts);
List<Account> accounts = new List<Account>{new Account()};
DmlOps.create(accounts, new DmlOps.Options(new Map<String, Object>{'loggerScenario' => 'Test Scenario'}));
List<Account> accounts = new List<Account>{new Account()};
DmlOps.create(accounts, new DmlOps.Options('{"loggingScenario": "Test Scenario1"}'));
Exceptions will be logged, and then thrown back to the caller.
List<Account> accounts = new List<Account>{new Account()};
try {
DmlOps.create(accounts, new DmlOps.Options('{"allOrNone": true}'));
} catch (DmlException e) {
// Handle as needed
}
List<Database.UpsertResult> upsertResults = DmlOps.upsrt(accountsToUpsert, new DmlOps.Options(new Map<String, Object>{ 'externalIdField' => Account.Some_External_Id__c }));