Skip to content

tomcarman/sf-nebula-dml-ops

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 

Repository files navigation

sf-nebula-dml-ops

  • Light wrapper for Salesforce DML Operations, that logs to Nebula Logger.
  • Requires Nebula Logger.

Usage

Methods

DML Operation DmlOps Method
Insert DmlOps.create()
Update DmlOps.modify()
Upsert DmlOps.upsrt()
Delete DmlOps.remove() // TODO

Parameters

All methods accept the below parameters

Parameter Type Required
records List Yes
options DmlOps.Options No

DmlOps.Options

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}

Examples

Insert Records

List<Account> accounts = new List<Account>{new Account()};
DmlOps.create(accounts);

Update Records

List<Account> accounts = [SELECT Id FROM Account LIMIT 1];
accounts[0].Name = null;
DmlOps.modify(accounts);

Insert Records - with results

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);

Insert Records with Options

List<Account> accounts = new List<Account>{new Account()};
DmlOps.Options options = new DmlOps.Options();
options.loggingScenario = 'Test Scenario';
DmlOps.create(accounts);

Options can also be passed as a Map

List<Account> accounts = new List<Account>{new Account()};
DmlOps.create(accounts, new DmlOps.Options(new Map<String, Object>{'loggerScenario' => 'Test Scenario'}));

Or as a JSON object

List<Account> accounts = new List<Account>{new Account()};
DmlOps.create(accounts, new DmlOps.Options('{"loggingScenario": "Test Scenario1"}'));

Insert with allOrNone = True

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
}

Upsert with an external key

List<Database.UpsertResult> upsertResults = DmlOps.upsrt(accountsToUpsert, new DmlOps.Options(new Map<String, Object>{ 'externalIdField' => Account.Some_External_Id__c }));

Example Logs

Log

Image

Log Entry

Image

Log Entry Details

Image

About

πŸ“‹ Light wrapper for Salesforce DML Operations, that logs to Nebula Logger.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages