Skip to content

Fix #1002: use org default LoggerSettings for anonymous logs - #1029

Open
RajPabnani03 wants to merge 1 commit into
jongpie:mainfrom
RajPabnani03:bugfix/issue-1002-anonymous-log-retention
Open

RajPabnani03 wants to merge 1 commit into
jongpie:mainfrom
RajPabnani03:bugfix/issue-1002-anonymous-log-retention

Conversation

@RajPabnani03

@RajPabnani03 RajPabnani03 commented Oct 1, 2026 •

Copy link
Copy Markdown

Summary

Fixes #1002 — Log__c records created without LoggedBy__c (e.g., logs created by external systems via LogEntryEvent__e platform events) skipped the org-level LoggerSettings__c and fell back to the metadata field default for LogRetentionDate__c (14 days), causing anonymous logs to be purged earlier than the configured retention policy.

In Logger.getUserSettings(Schema.User loggingUser), the org-defaults step was gated on loggingUser.Id != null, so anonymous contexts degenerated to "field default only":

// Before
if (loggingUserSettings == null && loggingUser.Id != null && LoggerSettings__c.getOrgDefaults().Id != null) { ... }

// After
if (loggingUserSettings == null && LoggerSettings__c.getOrgDefaults().Id != null) { ... }

Org defaults are org-wide and don't depend on a user ID, so the documented settings hierarchy — User → Profile → Org → Field Default — now applies consistently for anonymous logs as well. This also fixes the same gap in LogEntryEventHandler (which routes LogEntryEvent__e.LoggedById__c through the same method). The SetupOwnerId reassignment stays guarded on loggingUser.Id != null, since it only applies when a real user context exists.

Adds it_should_use_org_default_settings_when_user_is_null to Logger_Tests, covering a Schema.User with no Id/ProfileId.

Testing

Verified in a scratch org (Enterprise Edition, API v67): full nebula-logger/core deploy succeeded and the complete local Apex suite passed — 1260/1260 tests, 93% org-wide coverage — including the new it_should_use_org_default_settings_when_user_is_null.

When a Log__c record is created without a LoggedBy__c value (e.g., logs
created from LogEntryEvent__e platform events by external systems),
Logger.getUserSettings() skipped the org-level defaults because the
LoggerSettings__c.getOrgDefaults() check required a non-null user ID.
Anonymous logs then fell back to the field default values (e.g.,
LogRetentionDate__c default of 14 days) instead of the configured
org-level LoggerSettings__c.

The settings hierarchy is now consistently applied for anonymous
contexts: User -> Profile -> Org -> Field Default.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Anonymous Logs Use Field Default Instead of Org-Level Logger Settings for Retention Date

1 participant