Package Edition of Nebula Logger
Unlocked Package (Slack plugin, 04t5Y0000015oTT)
Package Version of Nebula Logger
v1.5.4.1 (Slack plugin) / v4.18.3.3 (core)
New Bug Summary
SlackLoggerPlugin.sendAsyncSlackNotifications() re-enqueues a Slack notification for a Log__c record that has already been sent, because it only checks SendSlackNotification__c and never checks whether SlackNotificationDate__c is already populated.
Root cause / reproduction
Logger.warn(...) / Logger.error(...) + Logger.saveLog() creates a Log__c record with SendSlackNotification__c = true (set by flagLogsForSlackNotification() on BEFORE_INSERT).
AFTER_INSERT calls sendAsyncSlackNotifications(), which enqueues a SlackLoggerPlugin queueable job (Job A).
- Job A's
execute(QueueableContext) sends the Slack notification, sets log.SlackNotificationDate__c = System.now(), and calls update sentLogs; (https://github.com/jongpie/NebulaLogger/blob/main/nebula-logger/plugins/slack/plugin/slack/classes/SlackLoggerPlugin.cls#L118).
- That
update re-fires the Log__c trigger, so execute(LoggerPlugin__mdt, LoggerTriggerableContext) runs again with AFTER_UPDATE, calling sendAsyncSlackNotifications() a second time.
sendAsyncSlackNotifications() only checks log.SendSlackNotification__c (https://github.com/jongpie/NebulaLogger/blob/main/nebula-logger/plugins/slack/plugin/slack/classes/SlackLoggerPlugin.cls#L138), which is still true (nothing ever clears it), so it enqueues another job (Job B) for the same, already-sent log.
- Job B sends a duplicate Slack notification, updates the record again, and the cycle repeats until Salesforce's queueable chain-depth limit stops it.
In our org this produced 3 duplicate Slack messages for a single Logger.warn() + Logger.error() call, confirmed via AsyncApexJob (3 separate SlackLoggerPlugin queueable executions, ~1-2 seconds apart, for one Log__c record).
Suggested fix
In sendAsyncSlackNotifications(), also require log.SlackNotificationDate__c == null before adding the log to logsToSend:
private void sendAsyncSlackNotifications() {
List<Log__c> logsToSend = new List<Log__c>();
for (Log__c log : this.logs) {
if (log.SendSlackNotification__c && log.SlackNotificationDate__c == null) {
logsToSend.add(log);
}
}
...
}
We applied this exact change locally and confirmed it resolves the issue (1 queueable execution / 1 Slack message per log, instead of 3). Happy to open a PR with this fix if useful.
Package Edition of Nebula Logger
Unlocked Package (Slack plugin,
04t5Y0000015oTT)Package Version of Nebula Logger
v1.5.4.1 (Slack plugin) / v4.18.3.3 (core)
New Bug Summary
SlackLoggerPlugin.sendAsyncSlackNotifications()re-enqueues a Slack notification for aLog__crecord that has already been sent, because it only checksSendSlackNotification__cand never checks whetherSlackNotificationDate__cis already populated.Root cause / reproduction
Logger.warn(...)/Logger.error(...)+Logger.saveLog()creates aLog__crecord withSendSlackNotification__c = true(set byflagLogsForSlackNotification()onBEFORE_INSERT).AFTER_INSERTcallssendAsyncSlackNotifications(), which enqueues aSlackLoggerPluginqueueable job (Job A).execute(QueueableContext)sends the Slack notification, setslog.SlackNotificationDate__c = System.now(), and callsupdate sentLogs;(https://github.com/jongpie/NebulaLogger/blob/main/nebula-logger/plugins/slack/plugin/slack/classes/SlackLoggerPlugin.cls#L118).updatere-fires theLog__ctrigger, soexecute(LoggerPlugin__mdt, LoggerTriggerableContext)runs again withAFTER_UPDATE, callingsendAsyncSlackNotifications()a second time.sendAsyncSlackNotifications()only checkslog.SendSlackNotification__c(https://github.com/jongpie/NebulaLogger/blob/main/nebula-logger/plugins/slack/plugin/slack/classes/SlackLoggerPlugin.cls#L138), which is stilltrue(nothing ever clears it), so it enqueues another job (Job B) for the same, already-sent log.In our org this produced 3 duplicate Slack messages for a single
Logger.warn()+Logger.error()call, confirmed viaAsyncApexJob(3 separateSlackLoggerPluginqueueable executions, ~1-2 seconds apart, for oneLog__crecord).Suggested fix
In
sendAsyncSlackNotifications(), also requirelog.SlackNotificationDate__c == nullbefore adding the log tologsToSend:We applied this exact change locally and confirmed it resolves the issue (1 queueable execution / 1 Slack message per log, instead of 3). Happy to open a PR with this fix if useful.