Describe the bug
When doCommitWork() executes, each stage helper method (e.g. publishBeforeEventsStarting) loops over every registered SObjectType and unconditionally executes its DML statement on the List stored in the stage's Map (e.g. EventBus.publish() called by m_dml.eventPublish(List), even if the List is empty or the SObject type is not appropriate for the operation (e.g. an empty list of a c custom object type is passed to EventBus.publish()). This executes a lot of unnecessary DML calls and creates a large number of internal error log messages in an org executing the method. In particular publishBeforeEventsStarting creates a logged error for every non-e type registered in the UOW on commit.
Can you please wrap the commit statements in an isEmpty() check? e.g. replace
This is admittedly a pretty minor bug that normally fails silently unless you're looking through event monitoring logs, but it would be very helpful in reducing splunk noise. Thanks.
To Reproduce
(Please provide a public github repo with a full SFDX project that demonstrates the problem. If the repro case can be followed with a single example Apex class against a scratch org with just the fflib-apex-common and fflib-apex-mocks project deployed into it, you don't need to provide a github repo)
Steps to reproduce the behavior:
Execute any existing positive unit test for fflib_SObjectUnitOfWork.
Observe that all commit stage methods execute DML even if no SObject was added to its List.
Expected behavior
DML should not execute on empty lists and empty lists of non-platform event types should not be passed to EventBus.publish.
Screenshots and text of error observed
If applicable, add screenshots to help explain your problem. Also, paste the text of the raw error into the issue as well so that it can be found by others via search.
Version
Did you try to reproduce the problem against the latest fflib-apex-common code? yes
Describe the bug When doCommitWork() executes, each stage helper method (e.g. publishBeforeEventsStarting) loops over every registered SObjectType and unconditionally executes its DML statement on the List stored in the stage's Map (e.g. EventBus.publish() called by m_dml.eventPublish(List), even if the List is empty or the SObject type is not appropriate for the operation (e.g. an empty list of a c custom object type is passed to EventBus.publish()). This executes a lot of unnecessary DML calls and creates a large number of internal error log messages in an org executing the method. In particular publishBeforeEventsStarting creates a logged error for every non-e type registered in the UOW on commit.
Can you please wrap the commit statements in an isEmpty() check? e.g. replace
with
This is admittedly a pretty minor bug that normally fails silently unless you're looking through event monitoring logs, but it would be very helpful in reducing splunk noise. Thanks.
To Reproduce
(Please provide a public github repo with a full SFDX project that demonstrates the problem. If the repro case can be followed with a single example Apex class against a scratch org with just the fflib-apex-common and fflib-apex-mocks project deployed into it, you don't need to provide a github repo)
Steps to reproduce the behavior:
Expected behavior DML should not execute on empty lists and empty lists of non-platform event types should not be passed to EventBus.publish.
Screenshots and text of error observed If applicable, add screenshots to help explain your problem. Also, paste the text of the raw error into the issue as well so that it can be found by others via search.
Version Did you try to reproduce the problem against the latest fflib-apex-common code? yes