Skip to content

Commit 57ffd2c

Browse files
TrangOuljongpie
andauthored
Bugfix: Allowing to log SObject without ID field (#912)
* Small scope creep - removed a few unnecessary method calls in LogBatchPurger_Tests --------- Co-authored-by: Jonathan Gillespie <jonathan.c.gillespie@gmail.com>
1 parent 8d50108 commit 57ffd2c

File tree

9 files changed

+55
-22
lines changed

9 files changed

+55
-22
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
The most robust observability solution for Salesforce experts. Built 100% natively on the platform, and designed to work seamlessly with Apex, Lightning Components, Flow, OmniStudio, and integrations.
77

8-
## Unlocked Package - v4.17.0
8+
## Unlocked Package - v4.17.1
99

10-
[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04tg70000000rNhAAI)
11-
[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04tg70000000rNhAAI)
10+
[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04tg7000000157JAAQ)
11+
[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04tg7000000157JAAQ)
1212
[![View Documentation](./images/btn-view-documentation.png)](https://github.com/jongpie/NebulaLogger/wiki)
1313

14-
`sf package install --wait 20 --security-type AdminsOnly --package 04tg70000000rNhAAI`
14+
`sf package install --wait 20 --security-type AdminsOnly --package 04tg7000000157JAAQ`
1515

1616
---
1717

nebula-logger/core/main/logger-engine/classes/LogEntryEventBuilder.cls

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,15 @@ global with sharing class LogEntryEventBuilder {
460460
this.logEntryEvent.RecordSObjectClassification__c = 'Unknown';
461461
this.logEntryEvent.RecordSObjectType__c = 'Unknown';
462462
} else {
463-
this.logEntryEvent.RecordId__c = record.Id;
463+
try {
464+
this.logEntryEvent.RecordId__c = record.Id;
465+
} catch (System.SObjectException sobjectException) {
466+
// Some SObject Types (such as Platform Events) do not have the ID field;
467+
// that's OK, just skip setting it.
468+
if (sobjectException.getMessage().contains('Invalid field Id') == false) {
469+
throw sobjectException;
470+
}
471+
}
464472
this.logEntryEvent.RecordSObjectClassification__c = getSObjectClassification(record.getSObjectType());
465473
this.logEntryEvent.RecordSObjectType__c = record.getSObjectType().toString();
466474
this.logEntryEvent.RecordSObjectTypeNamespace__c = getSObjectTypeNamespace(record.getSObjectType());

nebula-logger/core/main/logger-engine/classes/Logger.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
global with sharing class Logger {
1616
// There's no reliable way to get the version number dynamically in Apex
1717
@TestVisible
18-
private static final String CURRENT_VERSION_NUMBER = 'v4.17.0';
18+
private static final String CURRENT_VERSION_NUMBER = 'v4.17.1';
1919
private static final System.LoggingLevel FALLBACK_LOGGING_LEVEL = System.LoggingLevel.DEBUG;
2020
private static final List<LogEntryEventBuilder> LOG_ENTRIES_BUFFER = new List<LogEntryEventBuilder>();
2121
private static final String MISSING_SCENARIO_ERROR_MESSAGE = 'No logger scenario specified. A scenario is required for logging in this org.';

nebula-logger/core/main/logger-engine/lwc/logger/loggerService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import LoggerServiceTaskQueue from './loggerServiceTaskQueue';
1010
import getSettings from '@salesforce/apex/ComponentLogger.getSettings';
1111
import saveComponentLogEntries from '@salesforce/apex/ComponentLogger.saveComponentLogEntries';
1212

13-
const CURRENT_VERSION_NUMBER = 'v4.17.0';
13+
const CURRENT_VERSION_NUMBER = 'v4.17.1';
1414

1515
const CONSOLE_OUTPUT_CONFIG = {
1616
messagePrefix: `%c Nebula Logger ${CURRENT_VERSION_NUMBER} `,

nebula-logger/core/tests/log-management/classes/LogBatchPurger_Tests.cls

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ private class LogBatchPurger_Tests {
3030

3131
Date scheduledDeletionDate = System.today().addDays(-7);
3232
Log__c log = new Log__c(LogRetentionDate__c = scheduledDeletionDate);
33-
LoggerMockDataCreator.createDataBuilder(log).populateRequiredFields().getRecord();
33+
LoggerMockDataCreator.createDataBuilder(log).populateRequiredFields();
3434
insert log;
3535

3636
List<LogEntry__c> logEntries = new List<LogEntry__c>();
3737
for (Integer i = 0; i < NUMBER_OF_LOG_ENTRIES_TO_CREATE; i++) {
3838
LogEntry__c logEntry = new LogEntry__c(Log__c = log.Id, LoggingLevel__c = System.LoggingLevel.INFO.name());
39-
LoggerMockDataCreator.createDataBuilder(logEntry).populateRequiredFields().getRecord();
39+
LoggerMockDataCreator.createDataBuilder(logEntry).populateRequiredFields();
4040
logEntries.add(logEntry);
4141
}
4242
insert logEntries;
@@ -47,7 +47,7 @@ private class LogBatchPurger_Tests {
4747
List<LogEntryTag__c> logEntryTags = new List<LogEntryTag__c>();
4848
for (LogEntry__c logEntry : logEntries) {
4949
LogEntryTag__c logEntryTag = new LogEntryTag__c(LogEntry__c = logEntry.Id, Tag__c = tag.Id);
50-
LoggerMockDataCreator.createDataBuilder(logEntryTag).populateRequiredFields().getRecord();
50+
LoggerMockDataCreator.createDataBuilder(logEntryTag).populateRequiredFields();
5151
logEntryTags.add(logEntryTag);
5252
}
5353
insert logEntryTags;

nebula-logger/core/tests/logger-engine/classes/LogEntryEventBuilder_Tests.cls

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,7 @@ private class LogEntryEventBuilder_Tests {
14611461
}
14621462

14631463
@IsTest
1464-
static void it_should_set_record_fields_for_record_when_platform_event() {
1464+
static void it_should_set_record_fields_for_record_when_unpublished_platform_event() {
14651465
LogEntryEventBuilder builder = new LogEntryEventBuilder(getUserSettings(), System.LoggingLevel.INFO, true);
14661466
System.Assert.isNull(builder.getLogEntryEvent().RecordId__c);
14671467
System.Assert.isNull(builder.getLogEntryEvent().RecordJson__c);
@@ -1470,13 +1470,37 @@ private class LogEntryEventBuilder_Tests {
14701470
System.Assert.isNull(builder.getLogEntryEvent().RecordSObjectTypeNamespace__c);
14711471

14721472
// To avoid creating a new platform event just for testing purposes, Nebula Logger's LogEntryEvent__e is reused
1473-
LogEntryEvent__e platformEvent = new LogEntryEvent__e();
1474-
builder.setRecordId(platformEvent);
1473+
LogEntryEvent__e unpublishedPlatformEvent = new LogEntryEvent__e();
1474+
builder.setRecordId(unpublishedPlatformEvent);
14751475

14761476
System.Assert.areEqual(1, builder.getLogEntryEvent().RecordCollectionSize__c);
14771477
System.Assert.areEqual('Single', builder.getLogEntryEvent().RecordCollectionType__c);
14781478
System.Assert.isNull(builder.getLogEntryEvent().RecordId__c);
1479-
System.Assert.areEqual(System.JSON.serializePretty(platformEvent), builder.getLogEntryEvent().RecordJson__c);
1479+
System.Assert.areEqual(System.JSON.serializePretty(unpublishedPlatformEvent), builder.getLogEntryEvent().RecordJson__c);
1480+
System.Assert.areEqual('Platform Event Object', builder.getLogEntryEvent().RecordSObjectClassification__c);
1481+
System.Assert.areEqual(LogEntryEvent__e.SObjectType.toString(), builder.getLogEntryEvent().RecordSObjectType__c);
1482+
}
1483+
1484+
@IsTest
1485+
static void it_should_set_record_fields_for_record_when_published_platform_event() {
1486+
LogEntryEventBuilder builder = new LogEntryEventBuilder(getUserSettings(), System.LoggingLevel.INFO, true);
1487+
System.Assert.isNull(builder.getLogEntryEvent().RecordId__c);
1488+
System.Assert.isNull(builder.getLogEntryEvent().RecordJson__c);
1489+
System.Assert.isNull(builder.getLogEntryEvent().RecordSObjectClassification__c);
1490+
System.Assert.isNull(builder.getLogEntryEvent().RecordSObjectType__c);
1491+
System.Assert.isNull(builder.getLogEntryEvent().RecordSObjectTypeNamespace__c);
1492+
1493+
// To avoid creating a new platform event just for testing purposes, Nebula Logger's LogEntryEvent__e is reused
1494+
LogEntryEvent__e publishedPlatformEvent = new LogEntryEvent__e();
1495+
LoggerMockDataCreator.createDataBuilder(publishedPlatformEvent).populateRequiredFields();
1496+
System.EventBus.publish(publishedPlatformEvent);
1497+
System.Test.getEventBus().deliver();
1498+
builder.setRecordId(publishedPlatformEvent);
1499+
1500+
System.Assert.areEqual(1, builder.getLogEntryEvent().RecordCollectionSize__c);
1501+
System.Assert.areEqual('Single', builder.getLogEntryEvent().RecordCollectionType__c);
1502+
System.Assert.isNull(builder.getLogEntryEvent().RecordId__c);
1503+
System.Assert.areEqual(System.JSON.serializePretty(publishedPlatformEvent), builder.getLogEntryEvent().RecordJson__c);
14801504
System.Assert.areEqual('Platform Event Object', builder.getLogEntryEvent().RecordSObjectClassification__c);
14811505
System.Assert.areEqual(LogEntryEvent__e.SObjectType.toString(), builder.getLogEntryEvent().RecordSObjectType__c);
14821506
}

nebula-logger/managed-package/sfdx-project.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
"postInstallScript": "LoggerInstallHandler",
1212
"scopeProfiles": true,
1313
"ancestorVersion": "HIGHEST",
14-
"versionNumber": "4.17.0.NEXT",
15-
"versionName": "Summer '25 Release",
16-
"versionDescription": "View the v4.17.0 milestone in GitHub for the list of changes - https://github.com/jongpie/NebulaLogger/milestone/17?closed=1",
17-
"releaseNotesUrl": "https://github.com/jongpie/NebulaLogger/releases/tag/v4.17.0"
14+
"versionNumber": "4.18.0.NEXT",
15+
"versionName": "Winter '26 Release",
16+
"versionDescription": "View the v4.18.0 milestone in GitHub for the list of changes - https://github.com/jongpie/NebulaLogger/milestone/18?closed=1",
17+
"releaseNotesUrl": "https://github.com/jongpie/NebulaLogger/releases/tag/v4.18.0"
1818
}
1919
],
2020
"packageAliases": {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nebula-logger",
3-
"version": "4.17.0",
3+
"version": "4.17.1",
44
"description": "The most robust logger for Salesforce. Works with Apex, Lightning Components, Flow, Process Builder & Integrations. Designed for Salesforce admins, developers & architects.",
55
"author": "Jonathan Gillespie",
66
"license": "MIT",

sfdx-project.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"path": "./nebula-logger/core",
1010
"definitionFile": "./config/scratch-orgs/base-scratch-def.json",
1111
"scopeProfiles": true,
12-
"versionNumber": "4.17.0.NEXT",
13-
"versionName": "Summer '25 Release",
14-
"versionDescription": "Updated all metadata to API v64.0, added logEntryPageSection LWC to LogEntry__c page, improved testing in Apex & LWC",
12+
"versionNumber": "4.17.1.NEXT",
13+
"versionName": "Bugfix: Allowing to log SObject without ID field",
14+
"versionDescription": "Updated LogEntryEventBuilder to handle the few types of SObjects that do not have an Id field (most notably, Platform Events)",
1515
"postInstallUrl": "https://github.com/jongpie/NebulaLogger/wiki",
1616
"releaseNotesUrl": "https://github.com/jongpie/NebulaLogger/releases",
1717
"unpackagedMetadata": {
@@ -222,6 +222,7 @@
222222
"Nebula Logger - Core@4.16.4-bugfix:-logger-lwc-initialization-message": "04tKe0000011MyWIAU",
223223
"Nebula Logger - Core@4.16.5-capture-apex-cursor-transaction-limits": "04tKe0000011N4KIAU",
224224
"Nebula Logger - Core@4.17.0-summer-'25-release": "04tg70000000rNhAAI",
225+
"Nebula Logger - Core@4.17.1-bugfix:-allowing-to-log-sobject-without-id-field": "04tg7000000157JAAQ",
225226
"Nebula Logger - Core Plugin - Async Failure Additions": "0Ho5Y000000blO4SAI",
226227
"Nebula Logger - Core Plugin - Async Failure Additions@1.0.0": "04t5Y0000015lhiQAA",
227228
"Nebula Logger - Core Plugin - Async Failure Additions@1.0.1": "04t5Y0000015lhsQAA",

0 commit comments

Comments
 (0)