Skip to content

Commit

Permalink
Dynamic field visibility for LogEntry__c HTTP response header fields (#…
Browse files Browse the repository at this point in the history
…569)

* Added new checkbox fields on LogEntry__c for long textarea fields that didn't previously have an equivalent checkbox field

* Rewrote several tests in LogEntryHandler_Tests to be unit tests without DML

* Resolved #566 by updating LogEntryRecordPage.flexipage to have conditional visibility for the fields HttpResponseHeaderKeys__c and HttpResponseHeaders__c, based on the new checkbox field HasHttpResponseHeaders__c
  • Loading branch information
jongpie authored Oct 13, 2023
1 parent 4ede2fb commit f2fe85c
Show file tree
Hide file tree
Showing 16 changed files with 501 additions and 248 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

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

## Unlocked Package - v4.11.8
## Unlocked Package - v4.11.10

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

`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y000001OigJQAS`
`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y000001OigxQAC`

`sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y000001OigJQAS`
`sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y000001OigxQAC`

---

Expand Down
30 changes: 18 additions & 12 deletions nebula-logger/core/main/log-management/classes/LogEntryHandler.cls
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public without sharing class LogEntryHandler extends LoggerSObjectHandler {
protected override void executeBeforeInsert(List<SObject> triggerNew) {
this.logEntries = (List<LogEntry__c>) triggerNew;

this.setCheckboxFields();
this.setApexClassFields();
this.setComponentFields();
this.setFlowDefinitionFields();
this.setFlowVersionFields();
this.setRecordNames();
this.setCheckboxFields();
}

protected override void executeBeforeUpdate(Map<Id, SObject> triggerNewMap, Map<Id, SObject> triggerOldMap) {
Expand All @@ -43,17 +43,6 @@ public without sharing class LogEntryHandler extends LoggerSObjectHandler {
this.setCheckboxFields();
}

private void setCheckboxFields() {
// A formula field can't be used for checking if a long text area field is set/null
// So, this code handles maintaing some checkbox fields via Apex instead
for (LogEntry__c logEntry : this.logEntries) {
logEntry.HasExceptionStackTrace__c = logEntry.ExceptionStackTrace__c != null;
logEntry.HasInlineTags__c = logEntry.Tags__c != null;
logEntry.HasRecordJson__c = logEntry.RecordJson__c != null;
logEntry.HasStackTrace__c = logEntry.StackTrace__c != null;
}
}

private void setApexClassFields() {
List<String> apexClassNames = new List<String>();
List<LogEntry__c> apexLogEntries = new List<LogEntry__c>();
Expand Down Expand Up @@ -271,6 +260,23 @@ public without sharing class LogEntryHandler extends LoggerSObjectHandler {
}
}

private void setCheckboxFields() {
// Long textarea fields can't be used in filters for SOQL, list views, etc, and a formula field can't be used
// for checking if a long text area field is set/null...
// So, this code handles maintaining some checkbox fields via Apex instead
for (LogEntry__c logEntry : this.logEntries) {
logEntry.HasDatabaseResultJson__c = logEntry.DatabaseResultJson__c != null;
logEntry.HasExceptionStackTrace__c = logEntry.ExceptionStackTrace__c != null;
logEntry.HasHttpRequestBody__c = logEntry.HttpRequestBody__c != null;
logEntry.HasHttpResponseBody__c = logEntry.HttpResponseBody__c != null;
logEntry.HasHttpResponseHeaderKeys__c = logEntry.HttpResponseHeaderKeys__c != null;
logEntry.HasHttpResponseHeaders__c = logEntry.HttpResponseHeaders__c != null;
logEntry.HasInlineTags__c = logEntry.Tags__c != null;
logEntry.HasRecordJson__c = logEntry.RecordJson__c != null;
logEntry.HasStackTrace__c = logEntry.StackTrace__c != null;
}
}

private String getDisplayFieldApiName(Schema.SObjectType sobjectType) {
if (SOBJECT_TYPE_TO_DISPLAY_FIELD_NAME.containsKey(sobjectType)) {
return SOBJECT_TYPE_TO_DISPLAY_FIELD_NAME.get(sobjectType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,13 @@
</fieldInstanceProperties>
<fieldItem>Record.HttpResponseHeaderKeys__c</fieldItem>
<identifier>RecordHttpResponseHeaderKeys_cField1</identifier>
<visibilityRule>
<criteria>
<leftValue>{!Record.HasHttpResponseHeaders__c}</leftValue>
<operator>EQUAL</operator>
<rightValue>false</rightValue>
</criteria>
</visibilityRule>
</fieldInstance>
</itemInstances>
<itemInstances>
Expand All @@ -604,6 +611,13 @@
</fieldInstanceProperties>
<fieldItem>Record.HttpResponseHeaders__c</fieldItem>
<identifier>RecordHttpResponseHeaders_cField1</identifier>
<visibilityRule>
<criteria>
<leftValue>{!Record.HasHttpResponseHeaders__c}</leftValue>
<operator>EQUAL</operator>
<rightValue>true</rightValue>
</criteria>
</visibilityRule>
</fieldInstance>
</itemInstances>
<itemInstances>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>HasDatabaseResultJson__c</fullName>
<businessStatus>Active</businessStatus>
<complianceGroup>None</complianceGroup>
<defaultValue>false</defaultValue>
<externalId>false</externalId>
<label>Has Database Result JSON</label>
<securityClassification>Confidential</securityClassification>
<trackFeedHistory>false</trackFeedHistory>
<trackTrending>false</trackTrending>
<type>Checkbox</type>
</CustomField>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>HasHttpRequestBody__c</fullName>
<businessStatus>Active</businessStatus>
<complianceGroup>None</complianceGroup>
<defaultValue>false</defaultValue>
<externalId>false</externalId>
<label>Has HTTP Request Body</label>
<securityClassification>Confidential</securityClassification>
<trackFeedHistory>false</trackFeedHistory>
<trackTrending>false</trackTrending>
<type>Checkbox</type>
</CustomField>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>HasHttpResponseBody__c</fullName>
<businessStatus>Active</businessStatus>
<complianceGroup>None</complianceGroup>
<defaultValue>false</defaultValue>
<externalId>false</externalId>
<label>Has HTTP Response Body</label>
<securityClassification>Confidential</securityClassification>
<trackFeedHistory>false</trackFeedHistory>
<trackTrending>false</trackTrending>
<type>Checkbox</type>
</CustomField>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>HasHttpResponseHeaderKeys__c</fullName>
<businessStatus>Active</businessStatus>
<complianceGroup>None</complianceGroup>
<defaultValue>false</defaultValue>
<externalId>false</externalId>
<label>Has HTTP Response Header Keys</label>
<securityClassification>Confidential</securityClassification>
<trackFeedHistory>false</trackFeedHistory>
<trackTrending>false</trackTrending>
<type>Checkbox</type>
</CustomField>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>HasHttpResponseHeaders__c</fullName>
<businessStatus>Active</businessStatus>
<complianceGroup>None</complianceGroup>
<defaultValue>false</defaultValue>
<externalId>false</externalId>
<label>Has HTTP Response Headers</label>
<securityClassification>Confidential</securityClassification>
<trackFeedHistory>false</trackFeedHistory>
<trackTrending>false</trackTrending>
<type>Checkbox</type>
</CustomField>
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,11 @@
<field>LogEntry__c.FlowVersionRunInMode__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntry__c.HasDatabaseResultJson__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntry__c.HasDatabaseResult__c</field>
Expand All @@ -363,6 +368,26 @@
<field>LogEntry__c.HasException__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntry__c.HasHttpRequestBody__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntry__c.HasHttpResponseBody__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntry__c.HasHttpResponseHeaderKeys__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntry__c.HasHttpResponseHeaders__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntry__c.HasInlineTags__c</field>
Expand Down Expand Up @@ -393,6 +418,11 @@
<field>LogEntry__c.HttpRequestBody__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntry__c.HttpRequestCompressed__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntry__c.HttpRequestEndpoint__c</field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@
<editable>false</editable>
<field>LogEntry__c.FlowVersionRunInMode__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntry__c.HasDatabaseResultJson__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
Expand All @@ -203,6 +208,31 @@
<field>LogEntry__c.HasException__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntry__c.HasHttpRequestBody__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntry__c.HasHttpResponseBody__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntry__c.HasHttpResponseHeaderKeys__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntry__c.HasHttpResponseHeaders__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntry__c.HasInlineTags__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntry__c.HasRecordId__c</field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@
<field>LogEntry__c.FlowVersionRunInMode__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntry__c.HasDatabaseResultJson__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntry__c.HasDatabaseResult__c</field>
Expand All @@ -287,6 +292,26 @@
<field>LogEntry__c.HasException__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntry__c.HasHttpRequestBody__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntry__c.HasHttpResponseBody__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntry__c.HasHttpResponseHeaderKeys__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntry__c.HasHttpResponseHeaders__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntry__c.HasInlineTags__c</field>
Expand Down Expand Up @@ -317,6 +342,11 @@
<field>LogEntry__c.HttpRequestBody__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntry__c.HttpRequestCompressed__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntry__c.HttpRequestEndpoint__c</field>
Expand Down
2 changes: 1 addition & 1 deletion nebula-logger/core/main/logger-engine/classes/Logger.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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.11.8';
private static final String CURRENT_VERSION_NUMBER = 'v4.11.10';
private static final System.LoggingLevel FALLBACK_LOGGING_LEVEL = System.LoggingLevel.DEBUG;
private static final Set<String> IGNORED_APEX_CLASSES = initializeIgnoredApexClasses();
private static final List<LogEntryEventBuilder> LOG_ENTRIES_BUFFER = new List<LogEntryEventBuilder>();
Expand Down
2 changes: 1 addition & 1 deletion nebula-logger/core/main/logger-engine/lwc/logger/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { LightningElement, api } from 'lwc';
import { createLoggerService } from './loggerService';

const CURRENT_VERSION_NUMBER = 'v4.11.8';
const CURRENT_VERSION_NUMBER = 'v4.11.10';

export default class Logger extends LightningElement {
#loggerService = createLoggerService();
Expand Down
Loading

0 comments on commit f2fe85c

Please sign in to comment.