Skip to content

Commit

Permalink
Adds proper null handling for Database.DMLOptions.OptAllOrNone for DM…
Browse files Browse the repository at this point in the history
…L operations where that value hasn't been supplied
  • Loading branch information
jamessimone committed Oct 24, 2023
1 parent 80eb1ce commit bdab823
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions force-app/dml/DML.cls
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public virtual class DML implements IDML {
public DML setOptions(Database.DMLOptions options, System.AccessLevel accessLevel) {
if (options != null) {
this.options = options;
if (this.options.OptAllOrNone == null) {
this.options.OptAllOrNone = true;
}
}
this.accessLevel = accessLevel;
return this;
Expand Down
11 changes: 11 additions & 0 deletions force-app/dml/DMLTests.cls
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,15 @@ private class DMLTests {
Assert.areEqual(true, firstResult.isSuccess());
Assert.areEqual(true, secondResult.isSuccess());
}

@IsTest
static void upsertWithDefaultSetOptionsWorks() {
// on some code paths, like insert, OptAllOrNone not being initialized on Database.DMLOptions is fine
// but on upsert (and possibly other operations), that specific value is always checked
Contact con = new Contact(LastName = 'Upsert');

new DML().setOptions(new Database.DMLOptions(), System.AccessLevel.SYSTEM_MODE).doUpsert(con);

Assert.isNotNull(con.Id);
}
}

0 comments on commit bdab823

Please sign in to comment.