From 5f59b7a9d04e1e7f0d649e9712f82a74961db86d Mon Sep 17 00:00:00 2001 From: Jonathan Gillespie Date: Wed, 7 Sep 2022 22:06:13 -0400 Subject: [PATCH] Created new LoggerScenario__c custom object (#356) * Created new object LoggerScenario__c as a more robust replacement for the old text field, Log__c.Scenario__c * Added new object & fields to permission sets * Rearranged tab order in LoggerConsole to have logger settings, log entry event stream & logger scenarios at the top of the list * Small scope creep to update picklist values for various 'API Version' fields * Fixed a test failure in LoggerEngineDataSelector_Tests mentioned in #358 * Fixed a small issue with how the pipeline generates package version aliases, cleaned up sfdx-project.json & README files --- README.md | 8 +- .../LogManagementDataSelector.md | 22 ++- .../Log-Management/LoggerScenarioHandler.md | 27 +++ docs/apex/index.md | 4 + docs/lightning-components/Logger.md | 2 +- ...eter.UseFirstSpecifiedScenario.md-meta.xml | 2 +- ...tHandler.LoggerScenarioHandler.md-meta.xml | 25 +++ .../applications/LoggerConsole.app-meta.xml | 8 +- .../classes/LogEntryEventHandler.cls | 22 +++ .../log-management/classes/LogHandler.cls | 39 +++- .../classes/LogManagementDataSelector.cls | 11 +- .../classes/LoggerScenarioHandler.cls | 18 ++ .../LoggerScenarioHandler.cls-meta.xml | 5 + .../LogRecordPage.flexipage-meta.xml | 4 +- ...oggerScenarioRecordPage.flexipage-meta.xml | 177 +++++++++++++++++ .../layouts/Log__c-Log Layout.layout-meta.xml | 2 +- ...__c-Logger Scenario Layout.layout-meta.xml | 117 +++++++++++ .../ApexClassApiVersion__c.field-meta.xml | 13 +- ...VersionApiVersionRuntime__c.field-meta.xml | 13 +- .../fields/ApiVersion__c.field-meta.xml | 10 +- .../Log__c/fields/Scenario__c.field-meta.xml | 8 +- .../fields/ThemeDisplayed__c.field-meta.xml | 2 +- .../fields/TransactionId__c.field-meta.xml | 2 +- .../TransactionScenario__c.field-meta.xml | 18 ++ .../fields/UserLoggingLevel__c.field-meta.xml | 2 +- .../listViews/AllLogs.listView-meta.xml | 2 +- .../LogsToPurgeSoon.listView-meta.xml | 2 +- .../LoggerScenario__c.object-meta.xml | 181 ++++++++++++++++++ ...enarioCompactLayout.compactLayout-meta.xml | 10 + .../fields/UniqueId__c.field-meta.xml | 15 ++ .../listViews/All.listView-meta.xml | 13 ++ ...yAssignedLoggerScenarios.listView-meta.xml | 13 ++ .../LoggerAdmin.permissionset-meta.xml | 20 +- .../LoggerEndUser.permissionset-meta.xml | 60 ++++++ .../LoggerLogViewer.permissionset-meta.xml | 18 ++ .../Log__c.Manage.quickAction-meta.xml | 8 +- .../tabs/LoggerScenario__c.tab-meta.xml | 5 + .../triggers/LoggerScenario.trigger | 7 + .../triggers/LoggerScenario.trigger-meta.xml | 5 + .../main/logger-engine/classes/Logger.cls | 2 +- .../core/tests/LoggerCore.testSuite-meta.xml | 3 +- .../classes/LogEntryEventHandler_Tests.cls | 91 ++++++++- .../classes/LogHandler_Tests.cls | 13 +- .../LogManagementDataSelector_Tests.cls | 2 +- .../classes/LoggerScenarioHandler_Tests.cls | 77 ++++++++ .../LoggerScenarioHandler_Tests.cls-meta.xml | 5 + .../utilities/LoggerTestConfigurator.cls | 1 + .../classes/ComponentLogger_Tests.cls | 2 +- .../classes/FlowCollectionLogEntry_Tests.cls | 2 +- .../classes/FlowLogEntry_Tests.cls | 2 +- .../classes/FlowRecordLogEntry_Tests.cls | 2 +- .../LoggerEngineDataSelector_Tests.cls | 24 ++- .../managed-package/sfdx-project.json | 6 +- package.json | 2 +- .../create-and-install-package-version.ps1 | 3 +- ...nario-field-to-logger-scenario-object.apex | 25 +++ sfdx-project.json | 15 +- 57 files changed, 1116 insertions(+), 81 deletions(-) create mode 100644 docs/apex/Log-Management/LoggerScenarioHandler.md create mode 100644 nebula-logger/core/main/configuration/customMetadata/LoggerSObjectHandler.LoggerScenarioHandler.md-meta.xml create mode 100644 nebula-logger/core/main/log-management/classes/LoggerScenarioHandler.cls create mode 100644 nebula-logger/core/main/log-management/classes/LoggerScenarioHandler.cls-meta.xml create mode 100644 nebula-logger/core/main/log-management/flexipages/LoggerScenarioRecordPage.flexipage-meta.xml create mode 100644 nebula-logger/core/main/log-management/layouts/LoggerScenario__c-Logger Scenario Layout.layout-meta.xml create mode 100644 nebula-logger/core/main/log-management/objects/Log__c/fields/TransactionScenario__c.field-meta.xml create mode 100644 nebula-logger/core/main/log-management/objects/LoggerScenario__c/LoggerScenario__c.object-meta.xml create mode 100644 nebula-logger/core/main/log-management/objects/LoggerScenario__c/compactLayouts/LogScenarioCompactLayout.compactLayout-meta.xml create mode 100644 nebula-logger/core/main/log-management/objects/LoggerScenario__c/fields/UniqueId__c.field-meta.xml create mode 100644 nebula-logger/core/main/log-management/objects/LoggerScenario__c/listViews/All.listView-meta.xml create mode 100644 nebula-logger/core/main/log-management/objects/LoggerScenario__c/listViews/MyAssignedLoggerScenarios.listView-meta.xml create mode 100644 nebula-logger/core/main/log-management/tabs/LoggerScenario__c.tab-meta.xml create mode 100644 nebula-logger/core/main/log-management/triggers/LoggerScenario.trigger create mode 100644 nebula-logger/core/main/log-management/triggers/LoggerScenario.trigger-meta.xml create mode 100644 nebula-logger/core/tests/log-management/classes/LoggerScenarioHandler_Tests.cls create mode 100644 nebula-logger/core/tests/log-management/classes/LoggerScenarioHandler_Tests.cls-meta.xml create mode 100644 scripts/data/migrate-log-scenario-field-to-logger-scenario-object.apex diff --git a/README.md b/README.md index cc4548b01..0e1b4e047 100644 --- a/README.md +++ b/README.md @@ -5,17 +5,17 @@ Designed for Salesforce admins, developers & architects. A robust logger for Apex, Lightning Components, Flow, Process Builder & Integrations. -## Unlocked Package - v4.8.0 +## Unlocked Package - v4.8.1 -[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015lslQAA) -[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015lslQAA) +[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015luIQAQ) +[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015luIQAQ) [![View Documentation](./images/btn-view-documentation.png)](https://jongpie.github.io/NebulaLogger/) ## Managed Package - v4.8.0 [![Install Managed Package in a Sandbox](./images/btn-install-managed-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?mgd=true&p0=04t5Y0000015lsgQAA) [![Install Managed Package in Production](./images/btn-install-managed-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?mgd=true&p0=04t5Y0000015lsgQAA) -[![View Milestone](./images/btn-view-managed-package-milestone.png)](https://github.com/jongpie/NebulaLogger/milestone/8) +[![View Milestone](./images/btn-view-managed-package-milestone.png)](https://github.com/jongpie/NebulaLogger/milestone/8?closed=1) --- diff --git a/docs/apex/Log-Management/LogManagementDataSelector.md b/docs/apex/Log-Management/LogManagementDataSelector.md index d5e90be50..e6b1d72f8 100644 --- a/docs/apex/Log-Management/LogManagementDataSelector.md +++ b/docs/apex/Log-Management/LogManagementDataSelector.md @@ -223,6 +223,26 @@ Log\_\_c The matching `Log__c` record +#### `getLoggerScenariosById(List logScenarioIds)` → `List` + +Returns a `List<LoggerScenario__c>` of records with the specified log scenario IDs + +##### Parameters + +| Param | Description | +| ---------------- | ------------------------------------------------- | +| `logScenarioIds` | The list of `ID` of the `Log__c` records to query | + +##### Return + +**Type** + +List<LoggerScenario\_\_c> + +**Description** + +The list of matching `LoggerScenario__c` records + #### `getLogsById(List logIds)` → `List` Returns a `Log__c` record and its related `LogEntry__c` records @@ -243,7 +263,7 @@ List<Log\_\_c> The list of matching `Log__c` records -#### `getLogsByTransactionId(Set transactionIds)` → `List` +#### `getLogsByTransactionId(List transactionIds)` → `List` Returns a `List<Log__c>` of records with the specified transaction IDs diff --git a/docs/apex/Log-Management/LoggerScenarioHandler.md b/docs/apex/Log-Management/LoggerScenarioHandler.md new file mode 100644 index 000000000..086865861 --- /dev/null +++ b/docs/apex/Log-Management/LoggerScenarioHandler.md @@ -0,0 +1,27 @@ +--- +layout: default +--- + +## LoggerScenarioHandler class + +Handles trigger events for the `LoggerScenario__c` object + +--- + +### Methods + +#### `getSObjectType()` → `Schema.SObjectType` + +Returns SObject Type that the handler is responsible for processing + +##### Return + +**Type** + +Schema.SObjectType + +**Description** + +The instance of `SObjectType` + +--- diff --git a/docs/apex/index.md b/docs/apex/index.md index eca8354f1..8befad09d 100644 --- a/docs/apex/index.md +++ b/docs/apex/index.md @@ -116,6 +116,10 @@ Builds and sends email notifications when internal exceptions occur within the l Provides details to LWCs about Logger's `SObjects`, using `@AuraEnabled` properties +### [LoggerScenarioHandler](Log-Management/LoggerScenarioHandler) + +Handles trigger events for the `LoggerScenario__c` object + ### [LoggerSettingsController](Log-Management/LoggerSettingsController) Controller class for lwc `loggerSettings`, used to manage records in `LoggerSettings__c` diff --git a/docs/lightning-components/Logger.md b/docs/lightning-components/Logger.md index 3c5427ea2..7b38663e5 100644 --- a/docs/lightning-components/Logger.md +++ b/docs/lightning-components/Logger.md @@ -6,7 +6,7 @@
setScenario(scenario)

Sets the scenario name for the current transaction - this is stored in LogEntryEvent__e.Scenario__c - and Log__c.Scenario__c, and can be used to filter & group logs

+ and Log__c.TransactionScenario__c, and can be used to filter & group logs

error(message) LogEntryBuilder

Creates a new log entry with logging level == LoggingLevel.ERROR

diff --git a/nebula-logger/core/main/configuration/customMetadata/LoggerParameter.UseFirstSpecifiedScenario.md-meta.xml b/nebula-logger/core/main/configuration/customMetadata/LoggerParameter.UseFirstSpecifiedScenario.md-meta.xml index f9e9ce948..880834730 100644 --- a/nebula-logger/core/main/configuration/customMetadata/LoggerParameter.UseFirstSpecifiedScenario.md-meta.xml +++ b/nebula-logger/core/main/configuration/customMetadata/LoggerParameter.UseFirstSpecifiedScenario.md-meta.xml @@ -10,7 +10,7 @@ Description__c When enabled (default), the first value provided when calling Logger.setScenario(String) is used to set the field Log__c.Scenario__c, and any subsequent calls to Logger.setScenario(String) are ignored in the current transaction. When disabled, the last value provided when calling Logger.setScenario(String) is instead used. + >When enabled (default), the first value provided when calling Logger.setScenario(String) is used to set the field Log__c.TransactionScenario__c, and any subsequent calls to Logger.setScenario(String) are ignored in the current transaction. When disabled, the last value provided when calling Logger.setScenario(String) is instead used. Value__c diff --git a/nebula-logger/core/main/configuration/customMetadata/LoggerSObjectHandler.LoggerScenarioHandler.md-meta.xml b/nebula-logger/core/main/configuration/customMetadata/LoggerSObjectHandler.LoggerScenarioHandler.md-meta.xml new file mode 100644 index 000000000..1150fc20d --- /dev/null +++ b/nebula-logger/core/main/configuration/customMetadata/LoggerSObjectHandler.LoggerScenarioHandler.md-meta.xml @@ -0,0 +1,25 @@ + + + + false + + IsEnabled__c + true + + + SObjectHandlerApexClass__c + LoggerScenarioHandler + + + SObjectTypeOverride__c + + + + SObjectType__c + LoggerScenario__c + + diff --git a/nebula-logger/core/main/log-management/applications/LoggerConsole.app-meta.xml b/nebula-logger/core/main/log-management/applications/LoggerConsole.app-meta.xml index 7f3bda7a7..3b97e506c 100644 --- a/nebula-logger/core/main/log-management/applications/LoggerConsole.app-meta.xml +++ b/nebula-logger/core/main/log-management/applications/LoggerConsole.app-meta.xml @@ -12,12 +12,13 @@ false Console + LoggerSettings + LogEntryEventStream + LoggerScenario__c Log__c LogEntry__c LogEntryTag__c LoggerTag__c - LogEntryEventStream - LoggerSettings LogBatchPurge standard-report standard-Dashboard @@ -38,6 +39,9 @@ Log__c LogEntry__c + + LoggerScenario__c + Log__c diff --git a/nebula-logger/core/main/log-management/classes/LogEntryEventHandler.cls b/nebula-logger/core/main/log-management/classes/LogEntryEventHandler.cls index 83da9edb1..036266e7d 100644 --- a/nebula-logger/core/main/log-management/classes/LogEntryEventHandler.cls +++ b/nebula-logger/core/main/log-management/classes/LogEntryEventHandler.cls @@ -15,6 +15,7 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler { private static final String DEFAULT_STORAGE_LOCATION_NAME = 'CUSTOM_OBJECTS'; private static final Database.DmlOptions DML_OPTIONS = createDmlOptions(); private static final String GUEST_USER_TYPE = 'Guest'; + private static final Map SCENARIO_UNIQUE_ID_TO_SCENARIO = new Map(); private static final Map TRANSACTION_ID_TO_LOG = new Map(); @TestVisible @@ -53,6 +54,7 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler { this.logEntryEvents = this.filterLogEntryEventsToSave((List) triggerNew); if (this.logEntryEvents.isEmpty() == false) { + this.upsertLoggerScenarios(); this.upsertLogs(); this.upsertLogEntries(); this.appendRuleBasedTags(); @@ -72,6 +74,22 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler { return logEntryEventsToSave; } + private void upsertLoggerScenarios() { + for (LogEntryEvent__e logEntryEvent : this.logEntryEvents) { + if (String.isBlank(logEntryEvent.Scenario__c) == true || SCENARIO_UNIQUE_ID_TO_SCENARIO.containsKey(logEntryEvent.Scenario__c)) { + continue; + } + + LoggerScenario__c loggerScenario = new LoggerScenario__c(Name = logEntryEvent.Scenario__c, UniqueId__c = logEntryEvent.Scenario__c); + loggerScenario.setOptions(DML_OPTIONS); + SCENARIO_UNIQUE_ID_TO_SCENARIO.put(loggerScenario.UniqueId__c, loggerScenario); + } + + List upsertResults = LoggerDataStore.getDatabase() + .upsertRecords(SCENARIO_UNIQUE_ID_TO_SCENARIO.values(), Schema.LoggerScenario__c.UniqueId__c, System.Test.isRunningTest()); + LoggerEmailSender.sendErrorEmail(Schema.LoggerScenario__c.SObjectType, upsertResults); + } + private void upsertLogs() { // To avoid making a callout for every log for details retrieved from api.status.salesforce.com, // try to query recent logs first to see if there is a recent log with the details already populated @@ -143,6 +161,10 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler { UserType__c = logEntryEvent.UserType__c ); + if (String.isNotBlank(logEntryEvent.Scenario__c) == true && SCENARIO_UNIQUE_ID_TO_SCENARIO.containsKey(logEntryEvent.Scenario__c) == true) { + log.TransactionScenario__c = SCENARIO_UNIQUE_ID_TO_SCENARIO.get(logEntryEvent.Scenario__c).Id; + } + TRANSACTION_ID_TO_LOG.put(log.TransactionId__c, log); } diff --git a/nebula-logger/core/main/log-management/classes/LogHandler.cls b/nebula-logger/core/main/log-management/classes/LogHandler.cls index 8f6b3d10b..670875665 100644 --- a/nebula-logger/core/main/log-management/classes/LogHandler.cls +++ b/nebula-logger/core/main/log-management/classes/LogHandler.cls @@ -16,6 +16,7 @@ public without sharing class LogHandler extends LoggerSObjectHandler { private List logs; @TestVisible private Map oldLogsById; + private Map loggerScenariosById; /** * @description Returns SObject Type that the handler is responsible for processing @@ -27,6 +28,7 @@ public without sharing class LogHandler extends LoggerSObjectHandler { protected override void executeBeforeInsert(List triggerNew) { this.logs = (List) triggerNew; + this.loggerScenariosById = queryLoggerScenarios(this.logs); this.setClosedStatusFields(); // The log OwnerId field should support being manually changed, so only auto-set it on insert @@ -107,7 +109,7 @@ public without sharing class LogHandler extends LoggerSObjectHandler { } private void setParentLog() { - Set parentLogTransactionIds = new Set(); + List parentLogTransactionIds = new List(); for (Log__c log : this.logs) { if (String.isNotBlank(log.ParentLogTransactionId__c) == true) { parentLogTransactionIds.add(log.ParentLogTransactionId__c); @@ -131,7 +133,7 @@ public without sharing class LogHandler extends LoggerSObjectHandler { } private void setLogRetentionDetails() { - Map scenarioToScenarioRule = queryScenarioRules(this.logs); + Map scenarioToScenarioRule = queryLogScenarioRules(this.logs, this.loggerScenariosById); for (Log__c log : this.logs) { // If the retention date has already been populated, leave it as-is if (log.LogRetentionDate__c != null) { @@ -142,7 +144,11 @@ public without sharing class LogHandler extends LoggerSObjectHandler { LoggerSettings__c loggingUserSettings = getLoggingUserSettings(log); // Load the configured scenario rule (if one exists) - LogScenarioRule__mdt matchingScenarioRule = scenarioToScenarioRule.get(log.Scenario__c); + LogScenarioRule__mdt matchingScenarioRule; + if (log.TransactionScenario__c != null) { + LoggerScenario__c loggerScenario = this.loggerScenariosById.get(log.TransactionScenario__c); + matchingScenarioRule = scenarioToScenarioRule.get(loggerScenario.UniqueId__c); + } Integer daysToRetainLog = Integer.valueOf( matchingScenarioRule != null ? matchingScenarioRule.NumberOfDaysToRetainLogs__c : loggingUserSettings.DefaultNumberOfDaysToRetainLogs__c @@ -226,6 +232,27 @@ public without sharing class LogHandler extends LoggerSObjectHandler { return logStatusNameToStatus; } + private static Map queryLoggerScenarios(List logs) { + List loggerScenarioIds = new List(); + for (Log__c log : logs) { + if (log.TransactionScenario__c != null) { + loggerScenarioIds.add(log.TransactionScenario__c); + } + } + + Map loggerScenariosById = new Map(); + + if (loggerScenarioIds.isEmpty() == true) { + return loggerScenariosById; + } + + List matchingLoggerScenarios = LogManagementDataSelector.getInstance().getLoggerScenariosById(loggerScenarioIds); + if (matchingLoggerScenarios != null && matchingLoggerScenarios.isEmpty() == false) { + loggerScenariosById = new Map(matchingLoggerScenarios); + } + return loggerScenariosById; + } + private static Map queryQueues(List possibleQueueNames) { Map queuesByDeveloperName = new Map(); for (Group queue : LogManagementDataSelector.getInstance().getQueuesByDeveloperName(possibleQueueNames)) { @@ -242,11 +269,11 @@ public without sharing class LogHandler extends LoggerSObjectHandler { return usersByUsername; } - private static Map queryScenarioRules(List logs) { + private static Map queryLogScenarioRules(List logs, Map loggerScenariosById) { Set scenarios = new Set(); for (Log__c log : logs) { - if (log.Scenario__c != null) { - scenarios.add(log.Scenario__c); + if (log.TransactionScenario__c != null && loggerScenariosById.containsKey(log.TransactionScenario__c) == true) { + scenarios.add(loggerScenariosById.get(log.TransactionScenario__c).UniqueId__c); } } diff --git a/nebula-logger/core/main/log-management/classes/LogManagementDataSelector.cls b/nebula-logger/core/main/log-management/classes/LogManagementDataSelector.cls index 3e059ade9..6eb94a8b4 100644 --- a/nebula-logger/core/main/log-management/classes/LogManagementDataSelector.cls +++ b/nebula-logger/core/main/log-management/classes/LogManagementDataSelector.cls @@ -175,10 +175,19 @@ public without sharing class LogManagementDataSelector { * @param transactionIds The list of `String` transaction IDs of the `Log__c` records to query * @return The list of matching `Log__c` records */ - public List getLogsByTransactionId(Set transactionIds) { + public List getLogsByTransactionId(List transactionIds) { return [SELECT Id, TransactionId__c FROM Log__c WHERE TransactionId__c IN :transactionIds]; } + /** + * @description Returns a `List` of records with the specified log scenario IDs + * @param logScenarioIds The list of `ID` of the `Log__c` records to query + * @return The list of matching `LoggerScenario__c` records + */ + public List getLoggerScenariosById(List logScenarioIds) { + return [SELECT Id, OwnerId, UniqueId__c FROM LoggerScenario__c WHERE Id IN :logScenarioIds]; + } + /** * @description Returns a `List` of records with the specified profile IDs * @param profileIds The list of `ID` of the `Profile` records to query diff --git a/nebula-logger/core/main/log-management/classes/LoggerScenarioHandler.cls b/nebula-logger/core/main/log-management/classes/LoggerScenarioHandler.cls new file mode 100644 index 000000000..eac68f489 --- /dev/null +++ b/nebula-logger/core/main/log-management/classes/LoggerScenarioHandler.cls @@ -0,0 +1,18 @@ +//------------------------------------------------------------------------------------------------// +// This file is part of the Nebula Logger project, released under the MIT License. // +// See LICENSE file or go to https://github.com/jongpie/NebulaLogger for full license details. // +//------------------------------------------------------------------------------------------------// + +/** + * @group Log Management + * @description Handles trigger events for the `LoggerScenario__c` object + */ +public without sharing class LoggerScenarioHandler extends LoggerSObjectHandler { + /** + * @description Returns SObject Type that the handler is responsible for processing + * @return The instance of `SObjectType` + */ + public override Schema.SObjectType getSObjectType() { + return Schema.LoggerScenario__c.SObjectType; + } +} diff --git a/nebula-logger/core/main/log-management/classes/LoggerScenarioHandler.cls-meta.xml b/nebula-logger/core/main/log-management/classes/LoggerScenarioHandler.cls-meta.xml new file mode 100644 index 000000000..c47403d0b --- /dev/null +++ b/nebula-logger/core/main/log-management/classes/LoggerScenarioHandler.cls-meta.xml @@ -0,0 +1,5 @@ + + + 55.0 + Active + diff --git a/nebula-logger/core/main/log-management/flexipages/LogRecordPage.flexipage-meta.xml b/nebula-logger/core/main/log-management/flexipages/LogRecordPage.flexipage-meta.xml index a6cc540a7..d3e16ba8a 100644 --- a/nebula-logger/core/main/log-management/flexipages/LogRecordPage.flexipage-meta.xml +++ b/nebula-logger/core/main/log-management/flexipages/LogRecordPage.flexipage-meta.xml @@ -246,8 +246,8 @@ uiBehavior readonly - Record.Scenario__c - RecordScenario__cField + Record.TransactionScenario__c + RecordTransactionScenario__cField diff --git a/nebula-logger/core/main/log-management/flexipages/LoggerScenarioRecordPage.flexipage-meta.xml b/nebula-logger/core/main/log-management/flexipages/LoggerScenarioRecordPage.flexipage-meta.xml new file mode 100644 index 000000000..6d62b2c12 --- /dev/null +++ b/nebula-logger/core/main/log-management/flexipages/LoggerScenarioRecordPage.flexipage-meta.xml @@ -0,0 +1,177 @@ + + + + + + + collapsed + false + + + enableActionsConfiguration + false + + + enableActionsInNative + false + + + hideChatterActions + false + + + numVisibleActions + 10 + + force:highlightsPanel + force_highlightsPanel + + + header + Region + + + + + + parentFieldApiName + LoggerScenario__c.Id + + + relatedListApiName + Logs__r + + + relatedListComponentOverride + ADVGRID + + + rowsToDisplay + 30 + + + showActionBar + true + + force:relatedListSingleContainer + force_relatedListSingleContainer + + + relatedTabContent + Facet + + + + + + parentFieldApiName + LoggerScenario__c.Id + + + relatedListApiName + Histories + + + relatedListComponentOverride + ADVGRID + + + rowsToDisplay + 30 + + + showActionBar + true + + force:relatedListSingleContainer + force_relatedListSingleContainer2 + + + Facet-f057dac9-734a-4003-bfc0-0c452db10e0a + Facet + + + + + + context + RECORD + + forceChatter:exposedFeed + forceChatter_exposedFeed + + + Facet-75112b31-f7b2-4fb3-9690-338e5b295cb2 + Facet + + + + + + active + true + + + body + relatedTabContent + + + title + Logs + + flexipage:tab + relatedListsTab + + + + + + body + Facet-f057dac9-734a-4003-bfc0-0c452db10e0a + + + title + History + + flexipage:tab + flexipage_tab2 + + + + + + body + Facet-75112b31-f7b2-4fb3-9690-338e5b295cb2 + + + title + Standard.Tab.collaborate + + flexipage:tab + flexipage_tab + + + maintabs + Facet + + + + + + tabs + maintabs + + flexipage:tabset + flexipage_tabset + + + main + Region + + Log Scenario Record Page + LoggerScenario__c + + RecordPage + diff --git a/nebula-logger/core/main/log-management/layouts/Log__c-Log Layout.layout-meta.xml b/nebula-logger/core/main/log-management/layouts/Log__c-Log Layout.layout-meta.xml index 17435940c..c3c3dda3e 100644 --- a/nebula-logger/core/main/log-management/layouts/Log__c-Log Layout.layout-meta.xml +++ b/nebula-logger/core/main/log-management/layouts/Log__c-Log Layout.layout-meta.xml @@ -68,7 +68,7 @@ Readonly - Scenario__c + TransactionScenario__c Readonly diff --git a/nebula-logger/core/main/log-management/layouts/LoggerScenario__c-Logger Scenario Layout.layout-meta.xml b/nebula-logger/core/main/log-management/layouts/LoggerScenario__c-Logger Scenario Layout.layout-meta.xml new file mode 100644 index 000000000..3ecec04c0 --- /dev/null +++ b/nebula-logger/core/main/log-management/layouts/LoggerScenario__c-Logger Scenario Layout.layout-meta.xml @@ -0,0 +1,117 @@ + + + ChangeRecordType + PrintableView + Submit + + false + true + true + + + + Required + Name + + + Required + UniqueId__c + + + + + Edit + OwnerId + + + + + + false + true + true + + + + Readonly + CreatedById + + + + + Readonly + LastModifiedById + + + + + + true + false + true + + + + + + + + Record + + ChangeOwnerOne + StandardButton + 0 + + + Edit + StandardButton + 1 + + + Share + StandardButton + 2 + + + RecordShareHierarchy + StandardButton + 3 + + + Delete + StandardButton + 4 + + + + RelatedEntityHistoryList + + + MassDelete + New + NAME + LoggedByUsernameLink__c + StartTime__c + OWNER.ALIAS + Priority__c + Status__c + TransactionId__c + TotalLogEntries__c + TotalERRORLogEntries__c + TotalWARNLogEntries__c + Log__c.TransactionScenario__c + StartTime__c + Desc + + false + false + false + false + false + + 00h63000007c9rO + 4 + 0 + Default + + diff --git a/nebula-logger/core/main/log-management/objects/LogEntry__c/fields/ApexClassApiVersion__c.field-meta.xml b/nebula-logger/core/main/log-management/objects/LogEntry__c/fields/ApexClassApiVersion__c.field-meta.xml index fccb0be6b..0e399d1b0 100644 --- a/nebula-logger/core/main/log-management/objects/LogEntry__c/fields/ApexClassApiVersion__c.field-meta.xml +++ b/nebula-logger/core/main/log-management/objects/LogEntry__c/fields/ApexClassApiVersion__c.field-meta.xml @@ -17,14 +17,19 @@ false - v53.0 + v57.0 false - + - v52.0 + v56.0 false - + + + + v55.0 + false + diff --git a/nebula-logger/core/main/log-management/objects/LogEntry__c/fields/FlowVersionApiVersionRuntime__c.field-meta.xml b/nebula-logger/core/main/log-management/objects/LogEntry__c/fields/FlowVersionApiVersionRuntime__c.field-meta.xml index 0023535e6..12df2763a 100644 --- a/nebula-logger/core/main/log-management/objects/LogEntry__c/fields/FlowVersionApiVersionRuntime__c.field-meta.xml +++ b/nebula-logger/core/main/log-management/objects/LogEntry__c/fields/FlowVersionApiVersionRuntime__c.field-meta.xml @@ -18,14 +18,19 @@ false - v53.0 + v57.0 false - + - v52.0 + v56.0 false - + + + + v55.0 + false + diff --git a/nebula-logger/core/main/log-management/objects/Log__c/fields/ApiVersion__c.field-meta.xml b/nebula-logger/core/main/log-management/objects/Log__c/fields/ApiVersion__c.field-meta.xml index 95b92d1f4..c7da5678b 100644 --- a/nebula-logger/core/main/log-management/objects/Log__c/fields/ApiVersion__c.field-meta.xml +++ b/nebula-logger/core/main/log-management/objects/Log__c/fields/ApiVersion__c.field-meta.xml @@ -16,6 +16,11 @@ false + + v57.0 + false + + v56.0 false @@ -26,11 +31,6 @@ false - - v54.0 - false - - diff --git a/nebula-logger/core/main/log-management/objects/Log__c/fields/Scenario__c.field-meta.xml b/nebula-logger/core/main/log-management/objects/Log__c/fields/Scenario__c.field-meta.xml index bb66f1a4b..94d6865fb 100644 --- a/nebula-logger/core/main/log-management/objects/Log__c/fields/Scenario__c.field-meta.xml +++ b/nebula-logger/core/main/log-management/objects/Log__c/fields/Scenario__c.field-meta.xml @@ -1,15 +1,15 @@ Scenario__c - Active + DeprecateCandidate CCPA;GDPR;PII true - + 255 false Confidential - true - true + false + false false Text false diff --git a/nebula-logger/core/main/log-management/objects/Log__c/fields/ThemeDisplayed__c.field-meta.xml b/nebula-logger/core/main/log-management/objects/Log__c/fields/ThemeDisplayed__c.field-meta.xml index 3188e8645..10e32b92e 100644 --- a/nebula-logger/core/main/log-management/objects/Log__c/fields/ThemeDisplayed__c.field-meta.xml +++ b/nebula-logger/core/main/log-management/objects/Log__c/fields/ThemeDisplayed__c.field-meta.xml @@ -7,7 +7,7 @@ false Confidential - true + false false false Picklist diff --git a/nebula-logger/core/main/log-management/objects/Log__c/fields/TransactionId__c.field-meta.xml b/nebula-logger/core/main/log-management/objects/Log__c/fields/TransactionId__c.field-meta.xml index 1bcd4d4b6..683c4e862 100644 --- a/nebula-logger/core/main/log-management/objects/Log__c/fields/TransactionId__c.field-meta.xml +++ b/nebula-logger/core/main/log-management/objects/Log__c/fields/TransactionId__c.field-meta.xml @@ -9,7 +9,7 @@ 36 false Confidential - true + false false false Text diff --git a/nebula-logger/core/main/log-management/objects/Log__c/fields/TransactionScenario__c.field-meta.xml b/nebula-logger/core/main/log-management/objects/Log__c/fields/TransactionScenario__c.field-meta.xml new file mode 100644 index 000000000..3e23315b4 --- /dev/null +++ b/nebula-logger/core/main/log-management/objects/Log__c/fields/TransactionScenario__c.field-meta.xml @@ -0,0 +1,18 @@ + + + TransactionScenario__c + Active + CCPA;GDPR;PII + SetNull + false + + LoggerScenario__c + Logs + Logs + false + Confidential + true + true + false + Lookup + diff --git a/nebula-logger/core/main/log-management/objects/Log__c/fields/UserLoggingLevel__c.field-meta.xml b/nebula-logger/core/main/log-management/objects/Log__c/fields/UserLoggingLevel__c.field-meta.xml index c394ccb34..1c74b1773 100644 --- a/nebula-logger/core/main/log-management/objects/Log__c/fields/UserLoggingLevel__c.field-meta.xml +++ b/nebula-logger/core/main/log-management/objects/Log__c/fields/UserLoggingLevel__c.field-meta.xml @@ -7,7 +7,7 @@ false Confidential - true + false false false Picklist diff --git a/nebula-logger/core/main/log-management/objects/Log__c/listViews/AllLogs.listView-meta.xml b/nebula-logger/core/main/log-management/objects/Log__c/listViews/AllLogs.listView-meta.xml index 4164f8e46..4a87083ef 100644 --- a/nebula-logger/core/main/log-management/objects/Log__c/listViews/AllLogs.listView-meta.xml +++ b/nebula-logger/core/main/log-management/objects/Log__c/listViews/AllLogs.listView-meta.xml @@ -11,7 +11,7 @@ OWNER.ALIAS Priority__c Status__c - Scenario__c + TransactionScenario__c StartTime__c Everything diff --git a/nebula-logger/core/main/log-management/objects/Log__c/listViews/LogsToPurgeSoon.listView-meta.xml b/nebula-logger/core/main/log-management/objects/Log__c/listViews/LogsToPurgeSoon.listView-meta.xml index 4b1e004ac..9081ae2f6 100644 --- a/nebula-logger/core/main/log-management/objects/Log__c/listViews/LogsToPurgeSoon.listView-meta.xml +++ b/nebula-logger/core/main/log-management/objects/Log__c/listViews/LogsToPurgeSoon.listView-meta.xml @@ -7,7 +7,7 @@ OWNER.ALIAS Priority__c Status__c - Scenario__c + TransactionScenario__c StartTime__c LogPurgeAction__c LogRetentionDate__c diff --git a/nebula-logger/core/main/log-management/objects/LoggerScenario__c/LoggerScenario__c.object-meta.xml b/nebula-logger/core/main/log-management/objects/LoggerScenario__c/LoggerScenario__c.object-meta.xml new file mode 100644 index 000000000..ccc80c84b --- /dev/null +++ b/nebula-logger/core/main/log-management/objects/LoggerScenario__c/LoggerScenario__c.object-meta.xml @@ -0,0 +1,181 @@ + + + + Accept + Default + + + Accept + Large + Default + + + Accept + Small + Default + + + CancelEdit + Default + + + CancelEdit + Large + Default + + + CancelEdit + Small + Default + + + Clone + Default + + + Clone + Large + Default + + + Clone + Small + Default + + + Delete + Default + + + Delete + Large + Default + + + Delete + Small + Default + + + Edit + Default + + + Edit + Large + Default + + + Edit + Small + Default + + + List + Default + + + List + Large + Default + + + List + Small + Default + + + New + Default + + + New + Large + Default + + + New + Small + Default + + + SaveEdit + Default + + + SaveEdit + Large + Default + + + SaveEdit + Small + Default + + + Tab + Default + + + Tab + Large + Default + + + Tab + Small + Default + + + View + Action override created by Lightning App Builder during activation. + LoggerScenarioRecordPage + Large + false + Flexipage + + + View + Action override created by Lightning App Builder during activation. + LoggerScenarioRecordPage + Small + false + Flexipage + + + View + Default + + true + LogScenarioCompactLayout + Deployed + true + true + true + true + false + true + true + true + true + Private + + + + true + true + Text + + Logger Scenarios + + Accept + PrintableListView + Import + UniqueId__c + OWNER.ALIAS + CREATED_DATE + LAST_UPDATE + + Private + Public + diff --git a/nebula-logger/core/main/log-management/objects/LoggerScenario__c/compactLayouts/LogScenarioCompactLayout.compactLayout-meta.xml b/nebula-logger/core/main/log-management/objects/LoggerScenario__c/compactLayouts/LogScenarioCompactLayout.compactLayout-meta.xml new file mode 100644 index 000000000..bb7e07920 --- /dev/null +++ b/nebula-logger/core/main/log-management/objects/LoggerScenario__c/compactLayouts/LogScenarioCompactLayout.compactLayout-meta.xml @@ -0,0 +1,10 @@ + + + LogScenarioCompactLayout + Name + UniqueId__c + OwnerId + CreatedById + LastModifiedById + + diff --git a/nebula-logger/core/main/log-management/objects/LoggerScenario__c/fields/UniqueId__c.field-meta.xml b/nebula-logger/core/main/log-management/objects/LoggerScenario__c/fields/UniqueId__c.field-meta.xml new file mode 100644 index 000000000..f42d05a06 --- /dev/null +++ b/nebula-logger/core/main/log-management/objects/LoggerScenario__c/fields/UniqueId__c.field-meta.xml @@ -0,0 +1,15 @@ + + + UniqueId__c + false + true + An external ID field used to ensure that Logger Scenario records are unique + + 255 + true + true + true + false + Text + true + diff --git a/nebula-logger/core/main/log-management/objects/LoggerScenario__c/listViews/All.listView-meta.xml b/nebula-logger/core/main/log-management/objects/LoggerScenario__c/listViews/All.listView-meta.xml new file mode 100644 index 000000000..134d40625 --- /dev/null +++ b/nebula-logger/core/main/log-management/objects/LoggerScenario__c/listViews/All.listView-meta.xml @@ -0,0 +1,13 @@ + + + All + NAME + UniqueId__c + OWNER.ALIAS + CREATEDBY_USER + CREATED_DATE + UPDATEDBY_USER + LAST_UPDATE + Everything + + diff --git a/nebula-logger/core/main/log-management/objects/LoggerScenario__c/listViews/MyAssignedLoggerScenarios.listView-meta.xml b/nebula-logger/core/main/log-management/objects/LoggerScenario__c/listViews/MyAssignedLoggerScenarios.listView-meta.xml new file mode 100644 index 000000000..a2b4e9dfd --- /dev/null +++ b/nebula-logger/core/main/log-management/objects/LoggerScenario__c/listViews/MyAssignedLoggerScenarios.listView-meta.xml @@ -0,0 +1,13 @@ + + + MyAssignedLoggerScenarios + NAME + UniqueId__c + OWNER.ALIAS + CREATEDBY_USER + CREATED_DATE + UPDATEDBY_USER + LAST_UPDATE + Mine + + diff --git a/nebula-logger/core/main/log-management/permissionsets/LoggerAdmin.permissionset-meta.xml b/nebula-logger/core/main/log-management/permissionsets/LoggerAdmin.permissionset-meta.xml index 8db5d711f..6d201e6a1 100644 --- a/nebula-logger/core/main/log-management/permissionsets/LoggerAdmin.permissionset-meta.xml +++ b/nebula-logger/core/main/log-management/permissionsets/LoggerAdmin.permissionset-meta.xml @@ -976,7 +976,7 @@ true - false + true Log__c.Scenario__c true @@ -1085,6 +1085,11 @@ Log__c.TransactionId__c true + + true + Log__c.TransactionScenario__c + true + false Log__c.UserLicenseDefinitionKey__c @@ -1183,6 +1188,15 @@ Log__c true + + true + true + true + true + true + LoggerScenario__c + true + true true @@ -1212,6 +1226,10 @@ Log__c Visible + + LoggerScenario__c + Visible + LoggerSettings Visible diff --git a/nebula-logger/core/main/log-management/permissionsets/LoggerEndUser.permissionset-meta.xml b/nebula-logger/core/main/log-management/permissionsets/LoggerEndUser.permissionset-meta.xml index 1f0fad127..257756de7 100644 --- a/nebula-logger/core/main/log-management/permissionsets/LoggerEndUser.permissionset-meta.xml +++ b/nebula-logger/core/main/log-management/permissionsets/LoggerEndUser.permissionset-meta.xml @@ -43,6 +43,31 @@ Provides access to: - Generate log entries via Apex, Lightning Components, Flow and Process Builder. - View shared logs & log entries, based on OWD & sharing rules + + false + LogEntryTag__c.LogEntryOrigin__c + true + + + false + LogEntryTag__c.LogEntryTimestamp__c + true + + + false + LogEntryTag__c.LogLink__c + true + + + false + LogEntryTag__c.LoggedByUsernameLink__c + true + + + false + LogEntryTag__c.UniqueId__c + true + false LogEntry__c.ComponentApiName__c @@ -863,6 +888,11 @@ Log__c.TransactionId__c true + + false + Log__c.TransactionScenario__c + true + false Log__c.UserLicenseDefinitionKey__c @@ -929,6 +959,15 @@ LogEntryEvent__e false + + false + false + false + true + false + LogEntryTag__c + false + false false @@ -947,6 +986,15 @@ Log__c false + + false + false + false + true + false + LoggerScenario__c + false + false false @@ -956,10 +1004,22 @@ LoggerTag__c false + + LogEntryTag__c + Visible + + + LogEntry__c + Visible + Log__c Visible + + LoggerScenario__c + Visible + LoggerTag__c Visible diff --git a/nebula-logger/core/main/log-management/permissionsets/LoggerLogViewer.permissionset-meta.xml b/nebula-logger/core/main/log-management/permissionsets/LoggerLogViewer.permissionset-meta.xml index 625597c60..a54f40fce 100644 --- a/nebula-logger/core/main/log-management/permissionsets/LoggerLogViewer.permissionset-meta.xml +++ b/nebula-logger/core/main/log-management/permissionsets/LoggerLogViewer.permissionset-meta.xml @@ -1009,6 +1009,11 @@ Log__c.TransactionId__c true + + false + Log__c.TransactionScenario__c + true + false Log__c.UserLicenseDefinitionKey__c @@ -1107,6 +1112,15 @@ Log__c true + + false + false + false + true + false + LoggerScenario__c + true + false false @@ -1132,6 +1146,10 @@ Log__c Visible + + LoggerScenario__c + Visible + LoggerSettings Visible diff --git a/nebula-logger/core/main/log-management/quickActions/Log__c.Manage.quickAction-meta.xml b/nebula-logger/core/main/log-management/quickActions/Log__c.Manage.quickAction-meta.xml index 35958bec4..5b1e0965b 100644 --- a/nebula-logger/core/main/log-management/quickActions/Log__c.Manage.quickAction-meta.xml +++ b/nebula-logger/core/main/log-management/quickActions/Log__c.Manage.quickAction-meta.xml @@ -17,7 +17,7 @@ false - Scenario__c + TransactionScenario__c Edit @@ -27,17 +27,17 @@ false - Comments__c + LogRetentionDate__c Edit false - LogRetentionDate__c + LogPurgeAction__c Edit false - LogPurgeAction__c + Comments__c Edit diff --git a/nebula-logger/core/main/log-management/tabs/LoggerScenario__c.tab-meta.xml b/nebula-logger/core/main/log-management/tabs/LoggerScenario__c.tab-meta.xml new file mode 100644 index 000000000..92848eebe --- /dev/null +++ b/nebula-logger/core/main/log-management/tabs/LoggerScenario__c.tab-meta.xml @@ -0,0 +1,5 @@ + + + true + Custom57: Building Block + diff --git a/nebula-logger/core/main/log-management/triggers/LoggerScenario.trigger b/nebula-logger/core/main/log-management/triggers/LoggerScenario.trigger new file mode 100644 index 000000000..1ab7563ec --- /dev/null +++ b/nebula-logger/core/main/log-management/triggers/LoggerScenario.trigger @@ -0,0 +1,7 @@ +//------------------------------------------------------------------------------------------------// +// This file is part of the Nebula Logger project, released under the MIT License. // +// See LICENSE file or go to https://github.com/jongpie/NebulaLogger for full license details. // +//------------------------------------------------------------------------------------------------// +trigger LoggerScenario on LoggerScenario__c(before insert, before update, before delete, after insert, after update, after delete, after undelete) { + LoggerSObjectHandler.getHandler(Schema.LoggerScenario__c.SObjectType, new LoggerScenarioHandler()).execute(); +} diff --git a/nebula-logger/core/main/log-management/triggers/LoggerScenario.trigger-meta.xml b/nebula-logger/core/main/log-management/triggers/LoggerScenario.trigger-meta.xml new file mode 100644 index 000000000..bdd0bed9c --- /dev/null +++ b/nebula-logger/core/main/log-management/triggers/LoggerScenario.trigger-meta.xml @@ -0,0 +1,5 @@ + + + 55.0 + Active + diff --git a/nebula-logger/core/main/logger-engine/classes/Logger.cls b/nebula-logger/core/main/logger-engine/classes/Logger.cls index 348f38d76..8a2c660ad 100644 --- a/nebula-logger/core/main/logger-engine/classes/Logger.cls +++ b/nebula-logger/core/main/logger-engine/classes/Logger.cls @@ -13,7 +13,7 @@ global with sharing class Logger { // There's no reliable way to get the version number dynamically in Apex @TestVisible - private static final String CURRENT_VERSION_NUMBER = 'v4.8.0'; + private static final String CURRENT_VERSION_NUMBER = 'v4.8.1'; private static final LoggingLevel DEFAULT_LOGGING_LEVEL = LoggingLevel.DEBUG; private static final Set IGNORED_APEX_CLASSES = getIgnoredApexClasses(); private static final List LOG_ENTRIES_BUFFER = new List(); diff --git a/nebula-logger/core/tests/LoggerCore.testSuite-meta.xml b/nebula-logger/core/tests/LoggerCore.testSuite-meta.xml index 4f9d6cb24..79b6414a9 100644 --- a/nebula-logger/core/tests/LoggerCore.testSuite-meta.xml +++ b/nebula-logger/core/tests/LoggerCore.testSuite-meta.xml @@ -5,8 +5,8 @@ FlowLogEntry_Tests FlowLogger_Tests FlowRecordLogEntry_Tests - LogBatchPurger_Tests LogBatchPurgeController_Tests + LogBatchPurger_Tests LogBatchPurgeScheduler_Tests LogEntryEventBuilder_Tests LogEntryEventHandler_Tests @@ -20,6 +20,7 @@ LoggerEngineDataSelector_Tests LoggerParameter_Tests LoggerPlugin_Tests + LoggerScenarioHandler_Tests LoggerSettingsController_Tests LoggerSObjectHandler_Tests LoggerSObjectMetadata_Tests diff --git a/nebula-logger/core/tests/log-management/classes/LogEntryEventHandler_Tests.cls b/nebula-logger/core/tests/log-management/classes/LogEntryEventHandler_Tests.cls index 969a43555..981e05f86 100644 --- a/nebula-logger/core/tests/log-management/classes/LogEntryEventHandler_Tests.cls +++ b/nebula-logger/core/tests/log-management/classes/LogEntryEventHandler_Tests.cls @@ -3,7 +3,7 @@ // See LICENSE file or go to https://github.com/jongpie/NebulaLogger for full license details. // //------------------------------------------------------------------------------------------------// -@SuppressWarnings('PMD.ApexDoc, PMD.CyclomaticComplexity, PMD.ExcessiveParameterList, PMD.MethodNamingConventions, PMD.NcssMethodCount') +@SuppressWarnings('PMD.ApexDoc, PMD.CyclomaticComplexity, PMD.ExcessiveParameterList, PMD.MethodNamingConventions, PMD.NcssMethodCount, PMD.NcssTypeCount') @IsTest(IsParallel=true) private class LogEntryEventHandler_Tests { private static final String MOCK_RELEASE_NUMBER = '230.12.2'; @@ -90,12 +90,13 @@ private class LogEntryEventHandler_Tests { } @IsTest - static void it_should_normalize_event_data_into_log_and_log_entry() { + static void it_should_normalize_event_data_into_log_and_log_entry_when_no_scenario_specified() { LoggerDataStore.setMock(LoggerMockDataStore.getEventBus()); LoggerTestConfigurator.setupMockSObjectHandlerConfigurations(); LoggerTestConfigurator.getSObjectHandlerConfiguration(Schema.Log__c.SObjectType).IsEnabled__c = false; LoggerTestConfigurator.getSObjectHandlerConfiguration(Schema.LogEntry__c.SObjectType).IsEnabled__c = false; LogEntryEvent__e logEntryEvent = createLogEntryEvent(); + logEntryEvent.Scenario__c = null; Database.SaveResult saveResult = LoggerMockDataStore.getEventBus().publishRecord(logEntryEvent); LoggerMockDataStore.getEventBus().deliver(new LogEntryEventHandler()); @@ -107,6 +108,7 @@ private class LogEntryEventHandler_Tests { 'Handler class should have executed one time for AFTER_INSERT' ); Log__c log = getLog(); + System.assertEquals(null, log.TransactionScenario__c); System.assertEquals(1, log.LogEntries__r.size()); LogEntry__c logEntry = log.LogEntries__r.get(0); System.assertEquals(logEntryEvent.TransactionId__c, log.TransactionId__c); @@ -152,6 +154,73 @@ private class LogEntryEventHandler_Tests { } } + @IsTest + static void it_should_normalize_event_data_into_logger_scenario_and_log_and_log_entry_when_scenario_specified() { + LoggerDataStore.setMock(LoggerMockDataStore.getEventBus()); + LoggerTestConfigurator.setupMockSObjectHandlerConfigurations(); + LoggerTestConfigurator.getSObjectHandlerConfiguration(Schema.Log__c.SObjectType).IsEnabled__c = false; + LoggerTestConfigurator.getSObjectHandlerConfiguration(Schema.LogEntry__c.SObjectType).IsEnabled__c = false; + LogEntryEvent__e logEntryEvent = createLogEntryEvent(); + logEntryEvent.Scenario__c = '0'.repeat(Schema.LogEntryEvent__e.Scenario__c.getDescribe().getLength()); + + Database.SaveResult saveResult = LoggerMockDataStore.getEventBus().publishRecord(logEntryEvent); + LoggerMockDataStore.getEventBus().deliver(new LogEntryEventHandler()); + + System.assertEquals(true, saveResult.isSuccess(), saveResult.getErrors()); + System.assertEquals( + 1, + LoggerSObjectHandler.getExecutedHandlers().get(Schema.LogEntryEvent__e.SObjectType).size(), + 'Handler class should have executed one time for AFTER_INSERT' + ); + Log__c log = getLog(); + System.assertNotEquals(null, log.TransactionScenario__c); + System.assertEquals(1, log.LogEntries__r.size()); + LogEntry__c logEntry = log.LogEntries__r.get(0); + System.assertEquals(logEntryEvent.TransactionId__c, log.TransactionId__c); + validateLogFields(logEntryEvent, log); + validateLogEntryFields(logEntryEvent, logEntry); + } + + @IsTest + static void it_should_upsert_logger_scenarios_when_scenario_specified() { + LoggerDataStore.setMock(LoggerMockDataStore.getEventBus()); + LoggerTestConfigurator.setupMockSObjectHandlerConfigurations(); + LoggerTestConfigurator.getSObjectHandlerConfiguration(Schema.Log__c.SObjectType).IsEnabled__c = false; + LoggerTestConfigurator.getSObjectHandlerConfiguration(Schema.LogEntry__c.SObjectType).IsEnabled__c = false; + LoggerScenario__c existingLogScenario = new LoggerScenario__c(UniqueId__c = 'hello, world'); + insert existingLogScenario; + System.assertEquals(1, [SELECT COUNT() FROM LoggerScenario__c]); + LogEntryEvent__e firstLogEntryEvent = createLogEntryEvent(); + firstLogEntryEvent.Scenario__c = existingLogScenario.UniqueId__c; + LogEntryEvent__e secondLogEntryEvent = createLogEntryEvent(); + secondLogEntryEvent.Scenario__c = existingLogScenario.UniqueId__c; + List logEntryEvents = new List{ firstLogEntryEvent, secondLogEntryEvent }; + + List saveResults = LoggerMockDataStore.getEventBus().publishRecords(logEntryEvents); + LoggerMockDataStore.getEventBus().deliver(new LogEntryEventHandler()); + + System.assertEquals(logEntryEvents.size(), saveResults.size()); + for (Database.SaveResult saveResult : saveResults) { + System.assertEquals(true, saveResult.isSuccess(), saveResult.getErrors()); + } + System.assertEquals( + 1, + LoggerSObjectHandler.getExecutedHandlers().get(Schema.LogEntryEvent__e.SObjectType).size(), + 'Handler class should have executed one time for AFTER_INSERT' + ); + System.assertEquals(1, [SELECT COUNT() FROM LoggerScenario__c]); + Log__c log = getLog(); + System.assertEquals(existingLogScenario.Id, log.TransactionScenario__c); + System.assertEquals(logEntryEvents.size(), log.LogEntries__r.size()); + for (Integer i = 0; i < logEntryEvents.size(); i++) { + LogEntryEvent__e logEntryEvent = logEntryEvents.get(i); + LogEntry__c logEntry = log.LogEntries__r.get(i); + System.assertEquals(logEntryEvent.TransactionId__c, log.TransactionId__c); + validateLogFields(logEntryEvent, log); + validateLogEntryFields(logEntryEvent, logEntry); + } + } + @IsTest static void it_should_upsert_log_entries_when_event_uuid_is_populated() { LoggerDataStore.setMock(LoggerMockDataStore.getEventBus()); @@ -657,13 +726,13 @@ private class LogEntryEventHandler_Tests { logEntryEvent.LoggedById__c = UserInfo.getUserId(); logEntryEvent.LoggingLevel__c = LoggingLevel.INFO.name(); logEntryEvent.LoggingLevelOrdinal__c = LoggingLevel.INFO.ordinal(); - logEntryEvent.UserLoggingLevel__c = LoggingLevel.INFO.name(); - logEntryEvent.UserLoggingLevelOrdinal__c = LoggingLevel.INFO.ordinal(); logEntryEvent.ProfileId__c = UserInfo.getProfileId(); - logEntryEvent.TimestampString__c = String.valueOf(logEntryEvent.Timestamp__c.getTime()); - logEntryEvent.RecordId__c = UserInfo.getUserId(); logEntryEvent.RecordCollectionSize__c = 1; logEntryEvent.RecordCollectionType__c = 'Single'; + logEntryEvent.RecordId__c = UserInfo.getUserId(); + logEntryEvent.TimestampString__c = String.valueOf(logEntryEvent.Timestamp__c.getTime()); + logEntryEvent.UserLoggingLevel__c = LoggingLevel.INFO.name(); + logEntryEvent.UserLoggingLevelOrdinal__c = LoggingLevel.INFO.ordinal(); logEntryEvent = (LogEntryEvent__e) LoggerMockDataCreator.setReadOnlyField( logEntryEvent, Schema.LogEntryEvent__e.EventUuid, @@ -718,6 +787,9 @@ private class LogEntryEventHandler_Tests { TimeZoneId__c, TimeZoneName__c, TransactionId__c, + TransactionScenario__c, + TransactionScenario__r.Name, + TransactionScenario__r.UniqueId__c, UserLicenseDefinitionKey__c, UserLicenseId__c, UserLicenseName__c, @@ -836,7 +908,12 @@ private class LogEntryEventHandler_Tests { System.assertEquals(logEntryEvent.ParentLogTransactionId__c, log.ParentLogTransactionId__c, 'log.ParentLogTransactionId__c was not properly set'); System.assertEquals(logEntryEvent.ProfileId__c, log.ProfileId__c, 'log.ProfileId__c was not properly set'); System.assertEquals(logEntryEvent.ProfileName__c, log.ProfileName__c, 'log.ProfileName__c was not properly set'); - System.assertEquals(logEntryEvent.Scenario__c, log.Scenario__c, 'log.Scenario__c was not properly set'); + System.assertEquals( + logEntryEvent.Scenario__c?.left(Schema.LoggerScenario__c.Name.getDescribe().getLength()), + log.TransactionScenario__r?.Name, + 'log.TransactionScenario__c was not properly set' + ); + System.assertEquals(logEntryEvent.Scenario__c, log.TransactionScenario__r.UniqueId__c, 'log.TransactionScenario__r.UniqueId__c was not properly set'); System.assertEquals(logEntryEvent.SessionId__c, log.SessionId__c, 'log.SessionId__c was not properly set'); System.assertEquals(logEntryEvent.SessionId__c, log.SessionId__c, 'log.SessionId__c was not properly set'); System.assertEquals(logEntryEvent.SessionSecurityLevel__c, log.SessionSecurityLevel__c, 'log.SessionSecurityLevel__c was not properly set'); diff --git a/nebula-logger/core/tests/log-management/classes/LogHandler_Tests.cls b/nebula-logger/core/tests/log-management/classes/LogHandler_Tests.cls index 630e685e4..112e0a7a3 100644 --- a/nebula-logger/core/tests/log-management/classes/LogHandler_Tests.cls +++ b/nebula-logger/core/tests/log-management/classes/LogHandler_Tests.cls @@ -276,17 +276,22 @@ private class LogHandler_Tests { } @IsTest - static void it_should_set_retention_details_when_configured_via_scenario_rules() { + static void it_should_set_retention_details_when_configured_via_logger_scenario_rules() { setupConfigurations(); Integer defaultDaysToRetainLog = 1; Integer daysToRetainLog = 90; Date expectedRetentionDate = System.today().addDays(daysToRetainLog); Logger.getUserSettings().DefaultNumberOfDaysToRetainLogs__c = defaultDaysToRetainLog; upsert Logger.getUserSettings(); - String transactionScenarioName = 'some scenario'; - LoggerTestConfigurator.setMock(new LogScenarioRule__mdt(Scenario__c = transactionScenarioName, NumberOfDaysToRetainLogs__c = daysToRetainLog)); + LogScenarioRule__mdt logScenarioRule = new LogScenarioRule__mdt(Scenario__c = 'some scenario', NumberOfDaysToRetainLogs__c = daysToRetainLog); + LoggerTestConfigurator.setMock(logScenarioRule); + LoggerScenario__c logScenario = (LoggerScenario__c) LoggerMockDataCreator.createDataBuilder(Schema.LoggerScenario__c.SObjectType) + .populateRequiredFields() + .getRecord(); + logScenario.UniqueId__c = logScenarioRule.Scenario__c; + LoggerDataStore.getDatabase().insertRecord(logScenario); Log__c log = (Log__c) LoggerMockDataCreator.createDataBuilder(Schema.Log__c.SObjectType).populateRequiredFields().getRecord(); - log.Scenario__c = transactionScenarioName; + log.TransactionScenario__c = logScenario.Id; LoggerDataStore.getDatabase().insertRecord(log); diff --git a/nebula-logger/core/tests/log-management/classes/LogManagementDataSelector_Tests.cls b/nebula-logger/core/tests/log-management/classes/LogManagementDataSelector_Tests.cls index 97761782b..48f1fad2a 100644 --- a/nebula-logger/core/tests/log-management/classes/LogManagementDataSelector_Tests.cls +++ b/nebula-logger/core/tests/log-management/classes/LogManagementDataSelector_Tests.cls @@ -139,7 +139,7 @@ private class LogManagementDataSelector_Tests { static void it_returns_logs_for_specified_log_transaction_ids() { LoggerSObjectHandler.shouldExecute(false); List logs = new List(); - Set logTransactionIds = new Set(); + List logTransactionIds = new List(); for (Integer i = 0; i < 5; i++) { Log__c log = (Log__c) LoggerMockDataCreator.createDataBuilder(Schema.Log__c.SObjectType).populateRequiredFields().getRecord(); log.TransactionId__c = 'some_fake_transaction_id_' + i; diff --git a/nebula-logger/core/tests/log-management/classes/LoggerScenarioHandler_Tests.cls b/nebula-logger/core/tests/log-management/classes/LoggerScenarioHandler_Tests.cls new file mode 100644 index 000000000..5f54ade3b --- /dev/null +++ b/nebula-logger/core/tests/log-management/classes/LoggerScenarioHandler_Tests.cls @@ -0,0 +1,77 @@ +//------------------------------------------------------------------------------------------------// +// This file is part of the Nebula Logger project, released under the MIT License. // +// See LICENSE file or go to https://github.com/jongpie/NebulaLogger for full license details. // +//------------------------------------------------------------------------------------------------// + +@SuppressWarnings('PMD.ApexDoc, PMD.CyclomaticComplexity, PMD.ExcessiveParameterList, PMD.MethodNamingConventions, PMD.NcssMethodCount') +@IsTest(IsParallel=true) +private class LoggerScenarioHandler_Tests { + @IsTest + static void it_should_return_the_loggerScenario_sobjectType() { + System.assertEquals(Schema.LoggerScenario__c.SObjectType, new LoggerScenarioHandler().getSObjectType()); + } + + @IsTest + static void it_should_not_run_when_disabled_via_configuration() { + LoggerTestConfigurator.setupMockSObjectHandlerConfigurations(); + LoggerTestConfigurator.getSObjectHandlerConfiguration(Schema.LoggerScenario__c.SObjectType).IsEnabled__c = false; + LoggerScenario__c loggerScenario = (LoggerScenario__c) LoggerMockDataCreator.createDataBuilder(Schema.LoggerScenario__c.SObjectType) + .populateRequiredFields() + .getRecord(); + + LoggerDataStore.getDatabase().insertRecord(loggerScenario); + + System.assertEquals( + 0, + LoggerSObjectHandler.getExecutedHandlers().get(Schema.LoggerScenario__c.SObjectType).size(), + 'Handler class should not have executed' + ); + } + + @IsTest + static void it_should_run_when_enabled_via_configuration() { + LoggerTestConfigurator.setupMockSObjectHandlerConfigurations(); + LoggerTestConfigurator.getSObjectHandlerConfiguration(Schema.LoggerScenario__c.SObjectType).IsEnabled__c = true; + LoggerScenario__c loggerScenario = (LoggerScenario__c) LoggerMockDataCreator.createDataBuilder(Schema.LoggerScenario__c.SObjectType) + .populateRequiredFields() + .getRecord(); + + LoggerDataStore.getDatabase().insertRecord(loggerScenario); + + System.assertEquals( + 2, + LoggerSObjectHandler.getExecutedHandlers().get(Schema.LoggerScenario__c.SObjectType).size(), + 'Handler class should have executed two times - once for BEFORE_INSERT and once for AFTER_INSERT' + ); + } + + @IsTest + static void it_should_not_allow_duplicate_scenario_to_be_inserted() { + LoggerScenario__c loggerScenario = (LoggerScenario__c) LoggerMockDataCreator.createDataBuilder(Schema.LoggerScenario__c.SObjectType) + .populateRequiredFields() + .getRecord(); + loggerScenario.Name = 'Some log scenario name'; + LoggerDataStore.getDatabase().insertRecord(loggerScenario); + LoggerScenario__c duplicateScenario = (LoggerScenario__c) LoggerMockDataCreator.createDataBuilder(new LoggerScenario__c(Name = loggerScenario.Name)) + .populateRequiredFields() + .getRecord(); + Exception thrownException; + + try { + insert duplicateScenario; + System.assert(false, 'Exception expected on previous line'); + } catch (Exception ex) { + thrownException = ex; + } + + System.assertEquals( + 3, + LoggerSObjectHandler.getExecutedHandlers().get(Schema.LoggerScenario__c.SObjectType).size(), + 'Handler class should have executed three times - once for BEFORE_INSERT and once for AFTER_INSERT for the first record,' + + ' and once for BEFORE_INSERT on the errored duplicate' + ); + System.assertNotEquals(null, thrownException, 'An exception should have been thrown'); + String expectedDuplicateError = 'DUPLICATE_VALUE'; + System.assert(thrownException.getMessage().contains(expectedDuplicateError), thrownException.getMessage()); + } +} diff --git a/nebula-logger/core/tests/log-management/classes/LoggerScenarioHandler_Tests.cls-meta.xml b/nebula-logger/core/tests/log-management/classes/LoggerScenarioHandler_Tests.cls-meta.xml new file mode 100644 index 000000000..c47403d0b --- /dev/null +++ b/nebula-logger/core/tests/log-management/classes/LoggerScenarioHandler_Tests.cls-meta.xml @@ -0,0 +1,5 @@ + + + 55.0 + Active + diff --git a/nebula-logger/core/tests/log-management/utilities/LoggerTestConfigurator.cls b/nebula-logger/core/tests/log-management/utilities/LoggerTestConfigurator.cls index 6a9dc9cd3..5ab9d46f1 100644 --- a/nebula-logger/core/tests/log-management/utilities/LoggerTestConfigurator.cls +++ b/nebula-logger/core/tests/log-management/utilities/LoggerTestConfigurator.cls @@ -132,6 +132,7 @@ public without sharing class LoggerTestConfigurator { Schema.LogEntry__c.SObjectType => LogEntryHandler.class, Schema.LogEntryEvent__e.SObjectType => LogEntryEventHandler.class, Schema.LogEntryTag__c.SObjectType => LogEntryTagHandler.class, + Schema.LoggerScenario__c.SObjectType => LoggerScenarioHandler.class, Schema.LoggerTag__c.SObjectType => LoggerTagHandler.class }; for (Schema.SObjectType sobjectType : sobjectTypeToDefaultHandlerApexClass.keySet()) { diff --git a/nebula-logger/core/tests/logger-engine/classes/ComponentLogger_Tests.cls b/nebula-logger/core/tests/logger-engine/classes/ComponentLogger_Tests.cls index 56dabc00d..41bb75345 100644 --- a/nebula-logger/core/tests/logger-engine/classes/ComponentLogger_Tests.cls +++ b/nebula-logger/core/tests/logger-engine/classes/ComponentLogger_Tests.cls @@ -186,7 +186,7 @@ private class ComponentLogger_Tests { } @IsTest - static void it_should_set_log_scenario() { + static void it_should_set_logger_scenario() { LoggerDataStore.setMock(LoggerMockDataStore.getEventBus()); Logger.getUserSettings().LoggingLevel__c = LoggingLevel.FINEST.name(); ComponentLogger.ComponentLogEntry componentLogEntry = new ComponentLogger.ComponentLogEntry(); diff --git a/nebula-logger/core/tests/logger-engine/classes/FlowCollectionLogEntry_Tests.cls b/nebula-logger/core/tests/logger-engine/classes/FlowCollectionLogEntry_Tests.cls index 97a64cf9d..704dd6134 100644 --- a/nebula-logger/core/tests/logger-engine/classes/FlowCollectionLogEntry_Tests.cls +++ b/nebula-logger/core/tests/logger-engine/classes/FlowCollectionLogEntry_Tests.cls @@ -229,7 +229,7 @@ private class FlowCollectionLogEntry_Tests { } @IsTest - static void it_should_set_log_scenario() { + static void it_should_set_logger_scenario() { LoggerDataStore.setMock(LoggerMockDataStore.getEventBus()); LoggingLevel userLoggingLevel = LoggingLevel.FINEST; Logger.getUserSettings().LoggingLevel__c = userLoggingLevel.name(); diff --git a/nebula-logger/core/tests/logger-engine/classes/FlowLogEntry_Tests.cls b/nebula-logger/core/tests/logger-engine/classes/FlowLogEntry_Tests.cls index 5abbc94e2..69374d4bb 100644 --- a/nebula-logger/core/tests/logger-engine/classes/FlowLogEntry_Tests.cls +++ b/nebula-logger/core/tests/logger-engine/classes/FlowLogEntry_Tests.cls @@ -185,7 +185,7 @@ private class FlowLogEntry_Tests { } @IsTest - static void it_should_set_log_scenario() { + static void it_should_set_logger_scenario() { LoggerDataStore.setMock(LoggerMockDataStore.getEventBus()); LoggingLevel userLoggingLevel = LoggingLevel.FINEST; System.Test.startTest(); diff --git a/nebula-logger/core/tests/logger-engine/classes/FlowRecordLogEntry_Tests.cls b/nebula-logger/core/tests/logger-engine/classes/FlowRecordLogEntry_Tests.cls index e92507e6c..8a92dde1e 100644 --- a/nebula-logger/core/tests/logger-engine/classes/FlowRecordLogEntry_Tests.cls +++ b/nebula-logger/core/tests/logger-engine/classes/FlowRecordLogEntry_Tests.cls @@ -226,7 +226,7 @@ private class FlowRecordLogEntry_Tests { } @IsTest - static void it_should_set_log_scenario() { + static void it_should_set_logger_scenario() { LoggerDataStore.setMock(LoggerMockDataStore.getEventBus()); LoggingLevel userLoggingLevel = LoggingLevel.FINEST; Logger.getUserSettings().LoggingLevel__c = userLoggingLevel.name(); diff --git a/nebula-logger/core/tests/logger-engine/classes/LoggerEngineDataSelector_Tests.cls b/nebula-logger/core/tests/logger-engine/classes/LoggerEngineDataSelector_Tests.cls index c923a20ed..4e3ae27d3 100644 --- a/nebula-logger/core/tests/logger-engine/classes/LoggerEngineDataSelector_Tests.cls +++ b/nebula-logger/core/tests/logger-engine/classes/LoggerEngineDataSelector_Tests.cls @@ -8,15 +8,29 @@ private class LoggerEngineDataSelector_Tests { @IsTest static void it_returns_cached_auth_session() { - // AuthSession is always null in a test context, which makes this object/method more difficult to test - AuthSession expectedAuthSession = null; - System.assertEquals(0, Limits.getQueries()); + List sessions = [ + SELECT + Id, + LoginType, + LoginHistoryId, + LoginHistory.Application, + LoginHistory.Browser, + LoginHistory.Platform, + LogoutUrl, + SessionSecurityLevel, + SessionType, + SourceIp + FROM AuthSession + WHERE UsersId = :UserInfo.getUserId() AND IsCurrent = TRUE AND ParentId = NULL + ]; + AuthSession expectedAuthSession = sessions.isEmpty() ? null : sessions.get(0); + System.assertEquals(1, Limits.getQueries()); AuthSession returnedAuthSession = LoggerEngineDataSelector.getInstance().getCachedAuthSession(); - System.assertEquals(1, Limits.getQueries()); + System.assertEquals(2, Limits.getQueries()); LoggerEngineDataSelector.getInstance().getCachedAuthSession(); - System.assertEquals(1, Limits.getQueries(), 'Query results should have been cached'); + System.assertEquals(2, Limits.getQueries(), 'Query results should have been cached'); System.assertEquals(expectedAuthSession, returnedAuthSession); } diff --git a/nebula-logger/managed-package/sfdx-project.json b/nebula-logger/managed-package/sfdx-project.json index c777d6fba..4eacfb29a 100644 --- a/nebula-logger/managed-package/sfdx-project.json +++ b/nebula-logger/managed-package/sfdx-project.json @@ -10,9 +10,9 @@ "definitionFile": "./config/scratch-orgs/base-scratch-def.json", "postInstallScript": "LoggerInstallHandler", "ancestorVersion": "HIGHEST", - "versionNumber": "4.8.0.NEXT", - "versionName": "Summer '22 Release", - "versionDescription": "View the v4.8.0 milestone in GitHub for the list of changes - https://github.com/jongpie/NebulaLogger/milestone/8", + "versionNumber": "4.9.0.NEXT", + "versionName": "Winter '23 Release", + "versionDescription": "View the v4.9.0 milestone in GitHub for the list of changes - https://github.com/jongpie/NebulaLogger/milestone/9?closed=1", "releaseNotesUrl": "https://github.com/jongpie/NebulaLogger/releases" } ], diff --git a/package.json b/package.json index f1fd35239..a09b6e6be 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nebula-logger", - "version": "4.8.0", + "version": "4.8.1", "description": "Designed for Salesforce admins, developers & architects. A robust logger for Apex, Flow, Process Builder & Integrations.", "author": "Jonathan Gillespie", "license": "MIT", diff --git a/scripts/build/create-and-install-package-version.ps1 b/scripts/build/create-and-install-package-version.ps1 index 0583ae0b6..66c9a5119 100644 --- a/scripts/build/create-and-install-package-version.ps1 +++ b/scripts/build/create-and-install-package-version.ps1 @@ -53,7 +53,8 @@ function Get-Formatted-Package-Version-Number { # In sfdx-project.json, the packageDirectories section uses version number format W.X.Y.Z (all dots "." as delimiters) # but in packageAliases, it uses the format W.X.Y-Z (last delimiter is a dash "-") [int]$lastDotIndex = $packageVersionNumber.LastIndexOf('.') - $cleanedPackageVersionNumber = $packageVersionNumber.remove($lastDotIndex, 1).insert($lastDotIndex, "-") + $cleanedPackageVersionNumber = $packageVersionNumber.SubString(0, $lastDotIndex) + Write-Debug "Formatted Package Version Number $cleanedPackageVersionNumber" return $cleanedPackageVersionNumber } diff --git a/scripts/data/migrate-log-scenario-field-to-logger-scenario-object.apex b/scripts/data/migrate-log-scenario-field-to-logger-scenario-object.apex new file mode 100644 index 000000000..a9f2defe5 --- /dev/null +++ b/scripts/data/migrate-log-scenario-field-to-logger-scenario-object.apex @@ -0,0 +1,25 @@ +// Prior to v4.8.1, a log's scenario was stored in the text field Log__c.Scenario__c. +// In v4.8.1, a new LoggerScenario__c object was introduced, and the new lookup field Log__c.TransactionScenario__c +// replaces the text field Log__c.Scenario__c. This script handles migrating the text field's data into the new +// LoggerScenario__c object, and relates each Log__c record to the corresponding LoggerScenario__c record +Integer countOfRecordsToUpdate = [SELECT COUNT() FROM Log__c WHERE TransactionScenario__c = null AND Scenario__c != null]; +if (countOfRecordsToUpdate == 0) { + System.debug('No Log__c records to update! All data has been successfully migrated from Log__c.Scenario__c to the new lookup Log__c.TransactionScenario__c'); + return; +} + +System.debug(countOfRecordsToUpdate + ' Log__c records have legacy field Scenario__c set but not LoggerScenario__c'); + +Map scenarioNameToLogScenario = new Map(); +List logsToUpdate = [SELECT Id, TransactionScenario__c, Scenario__c FROM Log__c WHERE TransactionScenario__c = null AND Scenario__c != null LIMIT :Limits.getLimitDmlRows()]; +for (Log__c log : logsToUpdate) { + scenarioNameToLogScenario.put(log.TransactionScenario__r.UniqueId__c, log.TransactionScenario__r.clone()); + log.TransactionScenario__r = new LoggerScenario__c(UniqueId__c = log.Scenario__c); +} +upsert scenarioNameToLogScenario.values() UniqueId__c; +update logsToUpdate; + +countOfRecordsToUpdate = [SELECT COUNT() FROM Log__c WHERE TransactionScenario__c = null AND Scenario__c != null]; +if (countOfRecordsToUpdate > 0) { + System.debug(countOfRecordsToUpdate + ' additional Log__c records still to be updated! You will need to re-run this script to update additional Log__c records'); +} \ No newline at end of file diff --git a/sfdx-project.json b/sfdx-project.json index ed3568666..e14f61c78 100644 --- a/sfdx-project.json +++ b/sfdx-project.json @@ -12,9 +12,9 @@ "package": "Nebula Logger - Core", "path": "./nebula-logger/core", "definitionFile": "./config/scratch-orgs/base-scratch-def.json", - "versionNumber": "4.8.0.NEXT", - "versionName": "Ignore Origin Method", - "versionDescription": "Added new method Logger.ignoreOrigin() to ignore specified Apex types when parsing a log entry's origin", + "versionNumber": "4.8.1.NEXT", + "versionName": "New Logger Scenario Custom Object", + "versionDescription": "Added new custom object LoggerScenario__c to provide a more robust way to manage data related to scenario-based logging", "releaseNotesUrl": "https://github.com/jongpie/NebulaLogger/releases", "default": true }, @@ -126,10 +126,11 @@ "Nebula Logger - Core@4.7.3-2-query-selector-classes": "04t5Y0000015liHQAQ", "Nebula Logger - Core@4.7.4-3-new-method-logger.logdatabaseerrors()": "04t5Y0000015ligQAA", "Nebula Logger - Core@4.7.5-3-configurable-logger.setscenario()-behavior": "04t5Y0000015lkcQAA", - "Nebula Logger - Core@4.7.6-NEXT-support-for-component-logging-of-apex-controller-errors": "04t5Y0000015lkmQAA", - "Nebula Logger - Core@4.7.7-NEXT-bugfix-in-logger.setscenario()": "04t5Y0000015llLQAQ", - "Nebula Logger - Core@4.7.8-NEXT-new-'batch-purge'-lwc": "04t5Y0000015lmOQAQ", - "Nebula Logger - Core@4.8.0-NEXT-ignore-origin-method": "04t5Y0000015lslQAA", + "Nebula Logger - Core@4.7.6-support-for-component-logging-of-apex-controller-errors": "04t5Y0000015lkmQAA", + "Nebula Logger - Core@4.7.7-bugfix-in-logger.setscenario()": "04t5Y0000015llLQAQ", + "Nebula Logger - Core@4.7.8-new-'batch-purge'-lwc": "04t5Y0000015lmOQAQ", + "Nebula Logger - Core@4.8.0-ignore-origin-method": "04t5Y0000015lslQAA", + "Nebula Logger - Core@4.8.1-new-logger-scenario-custom-object": "04t5Y0000015luIQAQ", "Nebula Logger - Plugin - Async Failure Additions": "0Ho5Y000000blO4SAI", "Nebula Logger - Plugin - Async Failure Additions@1.0.0-3": "04t5Y0000015lhiQAA", "Nebula Logger - Plugin - Async Failure Additions@1.0.1-1": "04t5Y0000015lhsQAA",