Skip to content

Commit d04b6d7

Browse files
committed
#419 - updates README to call attention to UserModeDML and adds an optional constructor to UserModeDML to permit explicit SYSTEM_MODE
1 parent 3b4fa46 commit d04b6d7

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ FFLib Apex Common
1414
Updates
1515
=======
1616

17-
- **December 2022**, **IMPORTANT CHANGE** - Support for native Apex User Mode was added to the library (see [discussion](https://github.com/apex-enterprise-patterns/fflib-apex-common/discussions/419)). For new projects, the old `enforceCRUD` and `enforceFLS` flags on `fflib_SObjectSelector` should be considered deprecated and the constructors that take `dataAccess` arguments should be used instead. There are measurable performance benefits to using `SYSTEM_MODE` and `USER_MODE` (Apex CPU usage reduction).
17+
- **December 2022**, **IMPORTANT CHANGE** - Support for native Apex User Mode was added to the library (see [discussion](https://github.com/apex-enterprise-patterns/fflib-apex-common/discussions/419)). For new projects, the old `enforceCRUD` and `enforceFLS` flags on `fflib_SObjectSelector` should be considered deprecated and the constructors that take `dataAccess` arguments should be used instead. Additionally, the introduction of `fflib_SObjectUnitOfWork.UserModeDML` provides an `IDML` implementation that supports `USER_MODE` or `SYSTEM_MODE`. `fflib_SObjectUnitOfWork.SimpleDML` (the default `IDML` implementation) should be considered deprecated. There are measurable performance benefits to using `SYSTEM_MODE` and `USER_MODE` (Apex CPU usage reduction). Additionally, the use of explicit `USER_MODE` and `SYSTEM_MODE` overrides the `with sharing` and `without sharing` class declaration and makes the expected behavior of DML and SOQL easier to understand.
1818
- **April 2020**, **IMPORTANT CHANGE**, the directory format of this project repo was converted to [Salesforce DX Source Format](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_source_file_format.htm). While the GIT commit history was maintained, it is not visible on GitHub. If you need to see the history, either clone the repo and execute `git log --follow` from the command line or refer to this [tag](https://github.com/apex-enterprise-patterns/fflib-apex-common/tree/metadata-format-prior-to-dx-source-format-conversion) of the codebase prior to conversion.
1919
- **September 2014**, **IMPORTANT CHANGE**, changes applied to support Dreamforce 2014 advanced presentation, library now provides Application factories for major layers and support for ApexMocks. More details to follow! As a result [ApexMocks](https://github.com/apex-enterprise-patterns/fflib-apex-mocks) must be deployed to the org before deploying this library. The sample application [here](https://github.com/apex-enterprise-patterns/fflib-apex-common-samplecode) has also been updated to demonstrate the new features!
2020
- **July 2014**, **IMPORTANT CHANGE**, prior **23rd July 2014**, both the ``fflib_SObjectDomain.onValidate()`` and ``fflib_SObjectDomain.onValidate(Map<Id, SObject> existingRecords)`` methods where called during an on **after update** trigger event. From this point on the ``onValidate()`` method will only be called during on **after insert**. If you still require the orignal behaviour add the line ``Configuration.enableOldOnUpdateValidateBehaviour();`` into your constructor.

sfdx-source/apex-common/main/classes/fflib_SObjectUnitOfWork.cls

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,26 @@ public virtual class fflib_SObjectUnitOfWork
123123
}
124124

125125
public virtual class UserModeDML extends SimpleDML{
126+
@TestVisible
127+
private AccessLevel m_accessLevel;
128+
129+
public UserModeDML(){
130+
this(AccessLevel.USER_MODE);
131+
}
132+
133+
/** Supply the AccessLevel explicitly (UserModeDML uses AccessMode.USER_MODE, by default) */
134+
public UserModeDML(AccessLevel access){
135+
m_accessLevel = access;
136+
}
137+
126138
public virtual override void dmlInsert(List<SObject> objList){
127-
Database.insert(objList,AccessLevel.USER_MODE);
139+
Database.insert(objList,m_accessLevel);
128140
}
129141
public virtual override void dmlUpdate(List<SObject> objList){
130-
Database.update(objList,AccessLevel.USER_MODE);
142+
Database.update(objList,m_accessLevel);
131143
}
132144
public virtual override void dmlDelete(List<SObject> objList){
133-
Database.delete(objList,AccessLevel.USER_MODE);
145+
Database.delete(objList,m_accessLevel);
134146
}
135147
}
136148

sfdx-source/apex-common/test/classes/fflib_SObjectUnitOfWorkTest.cls

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,18 @@ private with sharing class fflib_SObjectUnitOfWorkTest
629629
System.assertEquals(1, mockDML.recordsForInsert.size());
630630
}
631631

632+
@IsTest
633+
private static void constructUserModeDML_When_DefaultConstructor_Expect_UserMode(){
634+
fflib_SObjectUnitOfWork.UserModeDML dml = new fflib_SObjectUnitOfWork.UserModeDML();
635+
System.assertEquals(AccessLevel.USER_MODE,dml.m_accessLevel);
636+
}
637+
638+
@IsTest
639+
private static void constructUserModeDML_When_AccessLevelSupplied_Expect_SameAccessLevel(){
640+
fflib_SObjectUnitOfWork.UserModeDML dml = new fflib_SObjectUnitOfWork.UserModeDML(AccessLevel.SYSTEM_MODE);
641+
System.assertEquals(AccessLevel.SYSTEM_MODE,dml.m_accessLevel);
642+
}
643+
632644
/**
633645
* Assert that actual events exactly match expected events (size, order and name)
634646
* and types match expected types

0 commit comments

Comments
 (0)