From f7359592b783543d39072eac6dffe91fe70df9aa Mon Sep 17 00:00:00 2001 From: Jonathan Gillespie Date: Wed, 30 Nov 2022 10:54:08 -0500 Subject: [PATCH] Added new field Log__c.HasComments__c (#418) * Added new field Log__c.HasComments__c to make it easier to filter on Log__c records that have a value populated in the long textarea field Log__c.Comments__c --- README.md | 6 +- .../log-management/classes/LogHandler.cls | 8 ++ .../fields/HasComments__c.field-meta.xml | 14 ++++ .../LoggerAdmin.permissionset-meta.xml | 5 ++ .../LoggerLogViewer.permissionset-meta.xml | 5 ++ .../main/logger-engine/classes/Logger.cls | 2 +- .../classes/LogHandler_Tests.cls | 81 +++++++++++++++++++ package.json | 2 +- sfdx-project.json | 7 +- 9 files changed, 122 insertions(+), 8 deletions(-) create mode 100644 nebula-logger/core/main/log-management/objects/Log__c/fields/HasComments__c.field-meta.xml diff --git a/README.md b/README.md index 254cc0b74..7d81b277f 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,10 @@ The most robust logger for Salesforce. Works with Apex, Lightning Components, Flow, Process Builder & Integrations. Designed for Salesforce admins, developers & architects. -## Unlocked Package - v4.9.6 +## Unlocked Package - v4.9.7 -[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000023R9eQAE) -[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000023R9eQAE) +[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000023R9yQAE) +[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000023R9yQAE) [![View Documentation](./images/btn-view-documentation.png)](https://jongpie.github.io/NebulaLogger/) ## Managed Package - v4.9.0 diff --git a/nebula-logger/core/main/log-management/classes/LogHandler.cls b/nebula-logger/core/main/log-management/classes/LogHandler.cls index 5b557f04a..3e7a3602e 100644 --- a/nebula-logger/core/main/log-management/classes/LogHandler.cls +++ b/nebula-logger/core/main/log-management/classes/LogHandler.cls @@ -29,6 +29,7 @@ public without sharing class LogHandler extends LoggerSObjectHandler { this.logs = (List) triggerNew; this.loggerScenariosById = queryLoggerScenarios(this.logs); + this.setHasCommentsField(); this.setClosedStatusFields(); // The log OwnerId field should support being manually changed, so only auto-set it on insert this.setOwnerId(); @@ -41,6 +42,7 @@ public without sharing class LogHandler extends LoggerSObjectHandler { this.logs = (List) triggerNewMap.values(); this.oldLogsById = (Map) triggerOldMap; + this.setHasCommentsField(); this.setClosedStatusFields(); // Priority logic relies on roll-up fields, so only run on update (after log entries are inserted) this.setPriority(); @@ -52,6 +54,12 @@ public without sharing class LogHandler extends LoggerSObjectHandler { this.shareLogsWithLoggingUsers(); } + private void setHasCommentsField() { + for (Log__c log : this.logs) { + log.HasComments__c = String.isNotBlank(log.Comments__c); + } + } + private void setClosedStatusFields() { Map logStatusNameToStatus = loadActiveLogStatuses(); for (Log__c log : this.logs) { diff --git a/nebula-logger/core/main/log-management/objects/Log__c/fields/HasComments__c.field-meta.xml b/nebula-logger/core/main/log-management/objects/Log__c/fields/HasComments__c.field-meta.xml new file mode 100644 index 000000000..e78430e0f --- /dev/null +++ b/nebula-logger/core/main/log-management/objects/Log__c/fields/HasComments__c.field-meta.xml @@ -0,0 +1,14 @@ + + + HasComments__c + Active + None + false + false + + Confidential + false + false + false + Checkbox + 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 1504897f3..30564dd47 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 @@ -784,6 +784,11 @@ Log__c.EndTime__c true + + false + Log__c.HasComments__c + true + false Log__c.ImpersonatedByUsernameLink__c 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 c061b8fd6..0d81b4db4 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 @@ -708,6 +708,11 @@ Log__c.EndTime__c true + + false + Log__c.HasComments__c + true + false Log__c.ImpersonatedByUsernameLink__c diff --git a/nebula-logger/core/main/logger-engine/classes/Logger.cls b/nebula-logger/core/main/logger-engine/classes/Logger.cls index 678fc7159..60859bcbb 100644 --- a/nebula-logger/core/main/logger-engine/classes/Logger.cls +++ b/nebula-logger/core/main/logger-engine/classes/Logger.cls @@ -15,7 +15,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.9.6'; + private static final String CURRENT_VERSION_NUMBER = 'v4.9.7'; private static final System.LoggingLevel FALLBACK_LOGGING_LEVEL = System.LoggingLevel.DEBUG; private static final Set IGNORED_APEX_CLASSES = initializeIgnoredApexClasses(); private static final List LOG_ENTRIES_BUFFER = new List(); 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 d38fbbe4e..8c3887408 100644 --- a/nebula-logger/core/tests/log-management/classes/LogHandler_Tests.cls +++ b/nebula-logger/core/tests/log-management/classes/LogHandler_Tests.cls @@ -36,6 +36,87 @@ private class LogHandler_Tests { System.Assert.areEqual(0, LoggerSObjectHandler.getExecutedHandlers().get(Schema.Log__c.SObjectType).size(), 'Handler class should not have executed'); } + @IsTest + static void it_should_set_hasComments_field_on_insert_when_comments_field_is_null() { + setupConfigurations(); + Log__c log = new Log__c(Comments__c = null, TransactionId__c = '1234'); + + LoggerDataStore.getDatabase().insertRecord(log); + + System.Assert.areEqual( + 2, + LoggerSObjectHandler.getExecutedHandlers().get(Schema.Log__c.SObjectType).size(), + 'Handler class should have executed two times - once for BEFORE_INSERT and once for AFTER_INSERT' + ); + log = [SELECT Id, Comments__c, HasComments__c FROM Log__c WHERE Id = :log.Id]; + System.Assert.isNull(log.Comments__c); + System.Assert.isFalse(log.HasComments__c); + } + + @IsTest + static void it_should_set_hasComments_field_on_insert_when_comments_field_is_not_null() { + setupConfigurations(); + String exampleComment = 'some comment'; + Log__c log = new Log__c(Comments__c = exampleComment, TransactionId__c = '1234'); + + LoggerDataStore.getDatabase().insertRecord(log); + + System.Assert.areEqual( + 2, + LoggerSObjectHandler.getExecutedHandlers().get(Schema.Log__c.SObjectType).size(), + 'Handler class should have executed two times - once for BEFORE_INSERT and once for AFTER_INSERT' + ); + log = [SELECT Id, Comments__c, HasComments__c FROM Log__c WHERE Id = :log.Id]; + System.Assert.areEqual(exampleComment, log.Comments__c); + System.Assert.isTrue(log.HasComments__c); + } + + @IsTest + static void it_should_set_hasComments_field_on_update_when_comments_field_is_null() { + setupConfigurations(); + String exampleComment = 'some comment'; + Log__c log = new Log__c(Comments__c = exampleComment, TransactionId__c = '1234'); + LoggerDataStore.getDatabase().insertRecord(log); + log = [SELECT Id, Comments__c, HasComments__c FROM Log__c WHERE Id = :log.Id]; + System.Assert.areEqual(exampleComment, log.Comments__c); + System.Assert.isTrue(log.HasComments__c); + log.Comments__c = null; + + LoggerDataStore.getDatabase().updateRecord(log); + + System.Assert.areEqual( + 4, + LoggerSObjectHandler.getExecutedHandlers().get(Schema.Log__c.SObjectType).size(), + 'Handler class should have executed four times - once for BEFORE_INSERT, AFTER_INSERT, BEFORE_UPDATE, and AFTER_UPDATE' + ); + log = [SELECT Id, Comments__c, HasComments__c FROM Log__c WHERE Id = :log.Id]; + System.Assert.isNull(log.Comments__c); + System.Assert.isFalse(log.HasComments__c); + } + + @IsTest + static void it_should_set_hasComments_field_on_update_when_comments_field_is_not_null() { + setupConfigurations(); + Log__c log = new Log__c(Comments__c = null, TransactionId__c = '1234'); + LoggerDataStore.getDatabase().insertRecord(log); + log = [SELECT Id, Comments__c, HasComments__c FROM Log__c WHERE Id = :log.Id]; + System.Assert.isNull(log.Comments__c); + System.Assert.isFalse(log.HasComments__c); + String exampleComment = 'some comment'; + log.Comments__c = exampleComment; + + LoggerDataStore.getDatabase().updateRecord(log); + + System.Assert.areEqual( + 4, + LoggerSObjectHandler.getExecutedHandlers().get(Schema.Log__c.SObjectType).size(), + 'Handler class should have executed four times - once for BEFORE_INSERT, AFTER_INSERT, BEFORE_UPDATE, and AFTER_UPDATE' + ); + log = [SELECT Id, Comments__c, HasComments__c FROM Log__c WHERE Id = :log.Id]; + System.Assert.areEqual(exampleComment, log.Comments__c); + System.Assert.isTrue(log.HasComments__c); + } + @IsTest static void it_should_clear_closed_status_fields_when_open() { setupConfigurations(); diff --git a/package.json b/package.json index 495825249..e3ec93e45 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nebula-logger", - "version": "4.9.6", + "version": "4.9.7", "description": "The most robust logger for Salesforce. Works with Apex, Lightning Components, Flow, Process Builder & Integrations. Designed for Salesforce admins, developers & architects.", "author": "Jonathan Gillespie", "license": "MIT", diff --git a/sfdx-project.json b/sfdx-project.json index de4dd9f0e..41a7f5abe 100644 --- a/sfdx-project.json +++ b/sfdx-project.json @@ -14,9 +14,9 @@ "package": "Nebula Logger - Core", "path": "./nebula-logger/core", "definitionFile": "./config/scratch-orgs/base-scratch-def.json", - "versionNumber": "4.9.6.NEXT", - "versionName": "Environment-Aware Default Field Values For Logger Settings", - "versionDescription": "Added new CMDT record LoggerParameter.PlatformCachePartitionName to control which platform cache partition is used for caching", + "versionNumber": "4.9.7.NEXT", + "versionName": "New Log Field HasComments", + "versionDescription": "Added new field Log__c.HasComments__c to make it easier to filter on Log__c records that have a value populated in the long textarea field Log__c.Comments__c", "releaseNotesUrl": "https://github.com/jongpie/NebulaLogger/releases", "unpackagedMetadata": { "path": "./nebula-logger/extra-tests" @@ -150,6 +150,7 @@ "Nebula Logger - Core@4.9.4-new-indicator-icons": "04t5Y0000023R8WQAU", "Nebula Logger - Core@4.9.5-configurable-platform-cache-partition-name": "04t5Y0000023R9KQAU", "Nebula Logger - Core@4.9.6-environment-aware-default-field-values-for-logger-settings": "04t5Y0000023R9eQAE", + "Nebula Logger - Core@4.9.7-new-log-field-hascomments": "04t5Y0000023R9yQAE", "Nebula Logger - Plugin - Async Failure Additions": "0Ho5Y000000blO4SAI", "Nebula Logger - Plugin - Async Failure Additions@1.0.0": "04t5Y0000015lhiQAA", "Nebula Logger - Plugin - Async Failure Additions@1.0.1": "04t5Y0000015lhsQAA",