From 5143519f5622249b712af7a239fa3a3841a6d9f2 Mon Sep 17 00:00:00 2001 From: Reinier van den Assum Date: Mon, 30 Nov 2026 09:20:12 +0100 Subject: [PATCH] fix(uow): enforce context access level when publishing platform events * Replace EventBus.publish with EventBus.publishWithAccessLevel in all DMLProxy implementations * FULL context now enforces USER_MODE (Create permission on the event) as documented; other contexts remain SYSTEM_MODE --- force-app/database/classes/dfflib_DatabaseTest.cls | 4 ++++ force-app/database/classes/dfflib_Database_DMLProxy.cls | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/force-app/database/classes/dfflib_DatabaseTest.cls b/force-app/database/classes/dfflib_DatabaseTest.cls index ac95bcb..cc19179 100644 --- a/force-app/database/classes/dfflib_DatabaseTest.cls +++ b/force-app/database/classes/dfflib_DatabaseTest.cls @@ -434,6 +434,7 @@ private with sharing class dfflib_DatabaseTest{ /** * As per Summer'24 (API v61.0), EventBus.publish(SObject event) returns a System.UnexpectedException when attempting to publish an SObject that represents an object that isn’t a platform event. + * EventBus.publishWithAccessLevel(SObject event, AccessLevel accessLevel), introduced in Summer'26 (API v67.0), behaves the same. * Therefore, only standard PlatformEvent or project-specific CustomEvent can be specified (though not being able to rely on) * Hence, covering as much lines as possible and ensuring those parts of code behave as expected */ @@ -920,6 +921,7 @@ private with sharing class dfflib_DatabaseTest{ /** * As per Summer'24 (API v61.0), EventBus.publish(SObject event) returns a System.UnexpectedException when attempting to publish an SObject that represents an object that isn’t a platform event. + * EventBus.publishWithAccessLevel(SObject event, AccessLevel accessLevel), introduced in Summer'26 (API v67.0), behaves the same. * Therefore, only standard PlatformEvent or project-specific CustomEvent can be specified (though not being able to rely on) * Hence, covering as much lines as possible and ensuring those parts of code behave as expected */ @@ -1419,6 +1421,7 @@ private with sharing class dfflib_DatabaseTest{ /** * As per Summer'24 (API v61.0), EventBus.publish(SObject event) returns a System.UnexpectedException when attempting to publish an SObject that represents an object that isn’t a platform event. + * EventBus.publishWithAccessLevel(SObject event, AccessLevel accessLevel), introduced in Summer'26 (API v67.0), behaves the same. * Therefore, only standard PlatformEvent or project-specific CustomEvent can be specified (though not being able to rely on) * Hence, covering as much lines as possible and ensuring those parts of code behave as expected */ @@ -1923,6 +1926,7 @@ private with sharing class dfflib_DatabaseTest{ /** * As per Summer'24 (API v61.0), EventBus.publish(SObject event) returns a System.UnexpectedException when attempting to publish an SObject that represents an object that isn’t a platform event. + * EventBus.publishWithAccessLevel(SObject event, AccessLevel accessLevel), introduced in Summer'26 (API v67.0), behaves the same. * Therefore, only standard PlatformEvent or project-specific CustomEvent can be specified (though not being able to rely on) * Hence, covering as much lines as possible and ensuring those parts of code behave as expected */ diff --git a/force-app/database/classes/dfflib_Database_DMLProxy.cls b/force-app/database/classes/dfflib_Database_DMLProxy.cls index 5bc7061..35b0835 100644 --- a/force-app/database/classes/dfflib_Database_DMLProxy.cls +++ b/force-app/database/classes/dfflib_Database_DMLProxy.cls @@ -77,7 +77,7 @@ public abstract class dfflib_Database_DMLProxy{ if( objList != null && !objList.isEmpty() ){ switch on action{ when dPUB_BEFORE, dPUB_AFTER_SUCCESS, dPUB_AFTER_FAILURE{ - return EventBus.publish( objList ); + return EventBus.publishWithAccessLevel( objList, accessLevel ); } when dEMPTY_RECBIN{ return Database.emptyRecycleBin( objList ); @@ -182,7 +182,7 @@ public abstract class dfflib_Database_DMLProxy{ if( objList != null && !objList.isEmpty() && accessLevel != null ){ switch on action{ when dPUB_BEFORE, dPUB_AFTER_SUCCESS, dPUB_AFTER_FAILURE{ - return EventBus.publish( objList ); + return EventBus.publishWithAccessLevel( objList, accessLevel ); } when dEMPTY_RECBIN{ return Database.emptyRecycleBin( objList ); @@ -287,7 +287,7 @@ public abstract class dfflib_Database_DMLProxy{ if( objList != null && !objList.isEmpty() && accessLevel != null ){ switch on action{ when dPUB_BEFORE, dPUB_AFTER_SUCCESS, dPUB_AFTER_FAILURE{ - return EventBus.publish( objList ); + return EventBus.publishWithAccessLevel( objList, accessLevel ); } when dEMPTY_RECBIN{ return Database.emptyRecycleBin( objList );