Skip to content

Commit

Permalink
Bugfix for LogEntryTags__c not being save with SYNCHRONOUS_DML save m…
Browse files Browse the repository at this point in the history
…ethod (#539)

* Added new field LogEntry__c.UniqueId__c to upsert LogEntry__c records

* Fixed SYNCHRONOUS_DML + tagging bug (#526) in LogEntryEventHandler by switching to new composite key field LogEntry__c.UniqueId__c to get tags

* Added new field LogEntry__c.UniqueId__c to FlexiPage LogEntryRecord and permission sets

* Scope creep: also added some conditional visibility rules in FlexiPage LogEntryRecord for the existing fields EntryScenarioLink__c and EventUuid__c
  • Loading branch information
JMercie committed Oct 4, 2023
1 parent 13f2faa commit a5a960f
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 42 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.6
## Unlocked Package - v4.11.7

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

`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y000001HZfGQAW`
`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y000001HZfaQAG`

`sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y000001HZfGQAW`
`sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y000001HZfaQAG`

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler {
@TestVisible
private List<LogEntryEvent__e> logEntryEvents;
private List<LogEntry__c> logEntries = new List<LogEntry__c>();
private Map<String, List<String>> logEntryEventUuidToTagNames = new Map<String, List<String>>();
private Map<String, List<String>> logEntryEventCompositeKeyToTagNames = new Map<String, List<String>>();
private Set<String> tagNames = new Set<String>();

/**
Expand Down Expand Up @@ -243,8 +243,6 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler {
}

private void upsertLogEntries() {
List<LogEntry__c> logEntriesWithUuid = new List<LogEntry__c>();
List<LogEntry__c> logEntriesWithoutUuid = new List<LogEntry__c>();
for (LogEntryEvent__e logEntryEvent : this.logEntryEvents) {
// Salesforce does not provide precise datetimes in Apex triggers for platform events
// Use the string value of timestamp to set the actual datetime field as a workaround
Expand Down Expand Up @@ -335,7 +333,8 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler {
TransactionEntryNumber__c = logEntryEvent.TransactionEntryNumber__c,
TriggerIsExecuting__c = logEntryEvent.TriggerIsExecuting__c,
TriggerOperationType__c = logEntryEvent.TriggerOperationType__c,
TriggerSObjectType__c = logEntryEvent.TriggerSObjectType__c
TriggerSObjectType__c = logEntryEvent.TriggerSObjectType__c,
UniqueId__c = logEntryEvent.TransactionId__c + '-' + logEntryEvent.TransactionEntryNumber__c
);

if (String.isNotBlank(logEntryEvent.EntryScenario__c) == true) {
Expand All @@ -352,21 +351,15 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler {

logEntry.setOptions(DML_OPTIONS);
this.logEntries.add(logEntry);
if (logEntry.EventUuid__c == null) {
logEntriesWithoutUuid.add(logEntry);
} else {
logEntriesWithUuid.add(logEntry);
if (logEntryEvent.Tags__c != null) {
List<String> logEntryTagNames = getTagNames(logEntryEvent.Tags__c);

this.tagNames.addAll(logEntryTagNames);
this.logEntryEventUuidToTagNames.put(logEntry.EventUuid__c, logEntryTagNames);
}

if (logEntryEvent.Tags__c != null) {
List<String> logEntryTagNames = getTagNames(logEntryEvent.Tags__c);
this.tagNames.addAll(logEntryTagNames);
this.logEntryEventCompositeKeyToTagNames.put(logEntry.UniqueId__c, logEntryTagNames);
}
}
List<Database.SaveResult> saveResults = LoggerDataStore.getDatabase().insertRecords(logEntriesWithoutUuid);
LoggerEmailSender.sendErrorEmail(Schema.LogEntry__c.SObjectType, saveResults);
List<Database.UpsertResult> upsertResults = LoggerDataStore.getDatabase().upsertRecords(logEntriesWithUuid, Schema.LogEntry__c.EventUuid__c);

List<Database.UpsertResult> upsertResults = LoggerDataStore.getDatabase().upsertRecords(this.logEntries, Schema.LogEntry__c.UniqueId__c);
LoggerEmailSender.sendErrorEmail(Schema.LogEntry__c.SObjectType, upsertResults);
}

Expand All @@ -380,13 +373,17 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler {
if (isRuleCriteriaMet(logEntry, rule) == true) {
List<String> configuredTagNames = getTagNames(rule.Tags__c);
this.tagNames.addAll(configuredTagNames);
List<String> logEntryTags = logEntryEventUuidToTagNames.get(logEntry.EventUuid__c);
List<String> logEntryTags = new List<String>();
if (this.logEntryEventCompositeKeyToTagNames.containsKey(logEntry.UniqueId__c) == true) {
logEntryTags = this.logEntryEventCompositeKeyToTagNames.get(logEntry.UniqueId__c);
}

if (logEntryTags == null) {
logEntryTags = new List<String>();
}
logEntryTags.addAll(configuredTagNames);

this.logEntryEventUuidToTagNames.put(logEntry.EventUuid__c, logEntryTags);
this.logEntryEventCompositeKeyToTagNames.put(logEntry.UniqueId__c, logEntryTags);
this.tagNames.addAll(logEntryTags);
}
}
Expand All @@ -407,14 +404,11 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler {
Schema.SObjectType tagAssignmentSObjectType;
Set<SObject> tagAssignments = new Set<SObject>();
for (LogEntry__c logEntry : this.logEntries) {
if (logEntry.EventUuid__c == null) {
if (this.logEntryEventCompositeKeyToTagNames.containsKey(logEntry.UniqueId__c) == false) {
continue;
}

List<String> logEntryTagNames = this.logEntryEventUuidToTagNames.get(logEntry.EventUuid__c);
if (logEntryTagNames == null || logEntryEventUuidToTagNames.isEmpty() == true) {
continue;
}
List<String> logEntryTagNames = this.logEntryEventCompositeKeyToTagNames.get(logEntry.UniqueId__c);

for (String tagName : logEntryTagNames) {
if (LoggerParameter.USE_TOPICS_FOR_TAGS == true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
</fieldInstanceProperties>
<fieldItem>Record.EntryScenario__c</fieldItem>
<identifier>RecordEntryScenario__cField</identifier>
<visibilityRule>
<criteria>
<leftValue>{!Record.EntryScenarioLink__c}</leftValue>
<operator>NE</operator>
</criteria>
</visibilityRule>
</fieldInstance>
</itemInstances>
<name>Facet-cb40f95d-9915-4ba5-815c-f3e53bcc4001</name>
Expand Down Expand Up @@ -125,6 +131,22 @@
</visibilityRule>
</fieldInstance>
</itemInstances>
<itemInstances>
<fieldInstance>
<fieldInstanceProperties>
<name>uiBehavior</name>
<value>readonly</value>
</fieldInstanceProperties>
<fieldItem>Record.UniqueId__c</fieldItem>
<identifier>RecordUniqueId_cField</identifier>
<visibilityRule>
<criteria>
<leftValue>{!Record.UniqueId__c}</leftValue>
<operator>NE</operator>
</criteria>
</visibilityRule>
</fieldInstance>
</itemInstances>
<itemInstances>
<fieldInstance>
<fieldInstanceProperties>
Expand All @@ -133,6 +155,12 @@
</fieldInstanceProperties>
<fieldItem>Record.EventUuid__c</fieldItem>
<identifier>RecordEventUuid__cField</identifier>
<visibilityRule>
<criteria>
<leftValue>{!Record.EventUuid__c}</leftValue>
<operator>NE</operator>
</criteria>
</visibilityRule>
</fieldInstance>
</itemInstances>
<name>Facet-f419a303-8d53-44e5-8647-63a464804568</name>
Expand Down Expand Up @@ -612,6 +640,10 @@
<name>columns</name>
<value>Facet-506803d6-0468-4ac1-a044-ede56cf84c05</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>horizontalAlignment</name>
<value>false</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>label</name>
<value>Information</value>
Expand All @@ -626,6 +658,10 @@
<name>columns</name>
<value>Facet-3a75f17f-589a-49f4-bdec-38f730e94676</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>horizontalAlignment</name>
<value>false</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>label</name>
<value>Message Details</value>
Expand All @@ -640,6 +676,10 @@
<name>columns</name>
<value>Facet-2a15cd64-78af-4727-8c6d-2913cb00a278</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>horizontalAlignment</name>
<value>false</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>label</name>
<value>Exception Information</value>
Expand All @@ -661,6 +701,10 @@
<name>columns</name>
<value>Facet-b0b8c0ec-36e3-469b-9106-00d34530d793</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>horizontalAlignment</name>
<value>false</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>label</name>
<value>Database Result</value>
Expand All @@ -682,6 +726,10 @@
<name>columns</name>
<value>Facet-f6d04c17-cbcd-40c6-aa58-c46313ecd8c4</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>horizontalAlignment</name>
<value>false</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>label</name>
<value>Related Record</value>
Expand Down Expand Up @@ -709,6 +757,10 @@
<name>columns</name>
<value>Facet-25eaa065-25af-4efc-9ce5-9d289a0fc3f0</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>horizontalAlignment</name>
<value>false</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>label</name>
<value>HTTP Request</value>
Expand All @@ -729,6 +781,10 @@
<name>columns</name>
<value>Facet-6395ceae-5694-468a-911f-714456910736</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>horizontalAlignment</name>
<value>false</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>label</name>
<value>HTTP Response</value>
Expand Down Expand Up @@ -945,6 +1001,10 @@
<name>columns</name>
<value>Facet-4fa5f475-f3a7-4ac0-b1cd-8285d7b369c7</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>horizontalAlignment</name>
<value>false</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>label</name>
<value>Limits</value>
Expand Down Expand Up @@ -1441,6 +1501,10 @@
<name>columns</name>
<value>Facet-defe921e-2975-4026-bfa5-1fe30baba592</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>horizontalAlignment</name>
<value>false</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>label</name>
<value>Tags</value>
Expand All @@ -1462,6 +1526,10 @@
<name>columns</name>
<value>Facet-a417c39b-b395-4d13-a87d-2d5bbb9d9d77</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>horizontalAlignment</name>
<value>false</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>label</name>
<value>Apex Class Information</value>
Expand All @@ -1488,6 +1556,10 @@
<name>columns</name>
<value>Facet-5f20b7f6-e40f-49b2-905b-5e2ca6c609e9</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>horizontalAlignment</name>
<value>false</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>label</name>
<value>Flow Information</value>
Expand All @@ -1509,6 +1581,10 @@
<name>columns</name>
<value>Facet-6b39517d-52f9-42f2-bf33-d392592baaa4</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>horizontalAlignment</name>
<value>false</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>label</name>
<value>Lightning Component Information</value>
Expand All @@ -1530,6 +1606,10 @@
<name>columns</name>
<value>Facet-81767854-f045-476a-a24f-aa790ad2f249</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>horizontalAlignment</name>
<value>false</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>label</name>
<value>Browser Information</value>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>UniqueId__c</fullName>
<caseSensitive>false</caseSensitive>
<description>Composite key that will hold the value of the TransactionId + TransactionEntryNumber</description>
<externalId>true</externalId>
<label>Unique ID</label>
<length>255</length>
<required>false</required>
<trackFeedHistory>false</trackFeedHistory>
<trackTrending>false</trackTrending>
<type>Text</type>
<unique>true</unique>
</CustomField>
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,11 @@
<field>LogEntry__c.Trigger__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>true</editable>
<field>LogEntryTag__c.UniqueId__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>Log__c.ApiReleaseNumber__c</field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,11 @@
<field>LogEntry__c.Trigger__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntryTag__c.UniqueId__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>Log__c.ApiReleaseNumber__c</field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,11 @@
<field>LogEntry__c.Trigger__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>LogEntryTag__c.UniqueId__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>Log__c.ApiReleaseNumber__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.6';
private static final String CURRENT_VERSION_NUMBER = 'v4.11.7';
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.6';
const CURRENT_VERSION_NUMBER = 'v4.11.7';

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

0 comments on commit a5a960f

Please sign in to comment.