Skip to content

Commit b0bec13

Browse files
authored
Bugfix for UserInfo.getSessionId() exception in connected apps with JWT enabled (#604)
* Fixed #598 by adding a try-catch block around the call to System.UserInfo.getSessionId() * Optimized how Logger.TRANSACTION_QUIDDITY is loaded so it doesn't repeatedly try to load in transactions where there isn't an active quiddity * Removed some extra copy-pasta in the new LoggerParameter__mdt record DefaultLogEntryRelatedListFieldSet
1 parent c1aeecd commit b0bec13

6 files changed

Lines changed: 24 additions & 25 deletions

File tree

README.md

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

66
The most robust logger for Salesforce. Works with Apex, Lightning Components, Flow, Process Builder & Integrations. Designed for Salesforce admins, developers & architects.
77

8-
## Unlocked Package - v4.12.2
8+
## Unlocked Package - v4.12.3
99

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

14-
`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y000001Mk55QAC`
14+
`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y000001Mk5AQAS`
1515

16-
`sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y000001Mk55QAC`
16+
`sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y000001Mk5AQAS`
1717

1818
---
1919

nebula-logger/core/main/configuration/customMetadata/LoggerParameter.DefaultLogEntryRelatedListFieldSet.md-meta.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
xsi:type="xsd:string"
1313
>The name of the LogEntry__c field set to use as the default field set when configuring the LWC <c-related-log-entries> within App Builder.
1414

15-
By default, the included field set partition &apos;Related_List_Defaults&apos; is used.</value>
15+
By default, the included field set &apos;Related_List_Defaults&apos; is used.</value>
1616
</values>
1717
<values>
1818
<field>Value__c</field>

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
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.12.2';
18+
private static final String CURRENT_VERSION_NUMBER = 'v4.12.3';
1919
private static final System.LoggingLevel FALLBACK_LOGGING_LEVEL = System.LoggingLevel.DEBUG;
2020
private static final Set<String> IGNORED_APEX_CLASSES = initializeIgnoredApexClasses();
2121
private static final List<LogEntryEventBuilder> LOG_ENTRIES_BUFFER = new List<LogEntryEventBuilder>();
2222
private static final String ORGANIZATION_DOMAIN_URL = System.URL.getOrgDomainUrl()?.toExternalForm();
2323
private static final String REQUEST_ID = System.Request.getCurrent().getRequestId();
2424
private static final Map<String, SaveMethod> SAVE_METHOD_NAME_TO_SAVE_METHOD = new Map<String, SaveMethod>();
2525
private static final String TRANSACTION_ID = new Uuid().getValue();
26+
private static final Quiddity TRANSACTION_QUIDDITY = loadTransactionQuiddity();
2627

2728
private static AsyncContext currentAsyncContext;
2829
private static String currentEntryScenario;
@@ -53,20 +54,16 @@ global with sharing class Logger {
5354
set;
5455
}
5556

56-
private static final Quiddity TRANSACTION_QUIDDITY {
57-
get {
58-
if (TRANSACTION_QUIDDITY == null) {
59-
TRANSACTION_QUIDDITY = getTransactionQuiddity();
60-
}
61-
return TRANSACTION_QUIDDITY;
62-
}
63-
set;
64-
}
65-
6657
private static final String USER_SESSION_ID {
6758
get {
6859
if (USER_SESSION_ID == null) {
69-
USER_SESSION_ID = System.UserInfo.getSessionId();
60+
// TODO Spring '24 release - simplify this (and other lazy-loaded values)
61+
// by switching to the fancy, new ?? null coalescing operator
62+
try {
63+
USER_SESSION_ID = System.UserInfo.getSessionId();
64+
} catch (Exception ex) {
65+
USER_SESSION_ID = '';
66+
}
7067
// If System.UserInfo.getSessionId() returns null, set to an empty string to
7168
// avoid calling System.UserInfo.getSessionId() again
7269
USER_SESSION_ID = USER_SESSION_ID == null ? '' : USER_SESSION_ID;
@@ -3385,7 +3382,7 @@ global with sharing class Logger {
33853382
return isStartTimeValid && isEndTimeValid;
33863383
}
33873384

3388-
private static Quiddity getTransactionQuiddity() {
3385+
private static Quiddity loadTransactionQuiddity() {
33893386
// An error can sometimes occur when calling System.Request.getCurrent(), such as when logging
33903387
// from an Auth Provider class (that implements Auth.RegistrationHandler). As a workaround,
33913388
// skip calling System.Request.getCurrent() if there is no user session.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { LightningElement, api } from 'lwc';
77
import { createLoggerService } from './loggerService';
88

9-
const CURRENT_VERSION_NUMBER = 'v4.12.2';
9+
const CURRENT_VERSION_NUMBER = 'v4.12.3';
1010

1111
export default class Logger extends LightningElement {
1212
#loggerService = createLoggerService();

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.12.2",
3+
"version": "4.12.3",
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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
"package": "Nebula Logger - Core",
1414
"path": "./nebula-logger/core",
1515
"definitionFile": "./config/scratch-orgs/base-scratch-def.json",
16-
"versionNumber": "4.12.2.NEXT",
17-
"versionName": "Automatically Select Default Field Set in relatedLogEntries LWC",
18-
"versionDescription": "Updated the relatedLogEntries LWC to automatically select the default field set when the component is added to a FlexiPage. The default field set name is configurable via LoggerParameter__mdt record DefaultLogEntryRelatedListFieldSet.",
16+
"versionNumber": "4.12.3.NEXT",
17+
"versionName": "Bugfix for UserInfo.getSessionId() Exception",
18+
"versionDescription": "Added a try-catch block to usage of UserInfo.getSessionId() to handle a platform-thrown exception that occurs in some transactions (such as connected apps with JWT).",
1919
"releaseNotesUrl": "https://github.com/jongpie/NebulaLogger/releases",
2020
"unpackagedMetadata": {
2121
"path": "./nebula-logger/extra-tests"
@@ -163,6 +163,7 @@
163163
"Nebula Logger - Core@4.12.0-winter-'24-release": "04t5Y000001Mk1wQAC",
164164
"Nebula Logger - Core@4.12.1-improved-error-emails": "04t5Y000001Mk4bQAC",
165165
"Nebula Logger - Core@4.12.2-automatically-select-default-field-set-in-relatedlogentries-lwc": "04t5Y000001Mk55QAC",
166+
"Nebula Logger - Core@4.12.3-bugfix-for-userinfo.getsessionid()-exception": "04t5Y000001Mk5AQAS",
166167
"Nebula Logger - Core Plugin - Async Failure Additions": "0Ho5Y000000blO4SAI",
167168
"Nebula Logger - Core Plugin - Async Failure Additions@1.0.0": "04t5Y0000015lhiQAA",
168169
"Nebula Logger - Core Plugin - Async Failure Additions@1.0.1": "04t5Y0000015lhsQAA",
@@ -180,5 +181,6 @@
180181
"Nebula Logger - Core Plugin - Slack@0.10.0": "04t5Y0000015lgQQAQ",
181182
"Nebula Logger - Core Plugin - Slack@1.5.0": "04t5Y0000015lvVQAQ",
182183
"Nebula Logger - Core Plugin - Slack@1.5.1": "04t5Y0000023Qu8QAE"
183-
}
184+
},
185+
"target-dev-hub": "sf.nebula.logger.package.bot@jongpie.com"
184186
}

0 commit comments

Comments
 (0)