Skip to content

Commit

Permalink
Picking #117 back up with @jongpie to finally add BigObject support t…
Browse files Browse the repository at this point in the history
…hrough Logger plugin package
  • Loading branch information
jamessimone committed Mar 16, 2022
1 parent fe39523 commit b6251fc
Show file tree
Hide file tree
Showing 110 changed files with 1,492 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler {
private Map<String, List<String>> logEntryEventUuidToTagNames = new Map<String, List<String>>();
private Set<String> tagNames = new Set<String>();

public LogEntryEventHandler() {
super();
}

public LogEntryEventHandler(List<LogEntryEvent__e> logEntryEvents, TriggerOperation triggerOperationType) {
this();
this.logEntryEvents = logEntryEvents;
this.input.triggerNew = logEntryEvents;
this.input.triggerOperationType = triggerOperationType;
this.input.triggerOperationTypeName = triggerOperationType.name();
}

/**
* @description Returns SObject Type that the handler is responsible for processing
* @return The instance of `SObjectType`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public without sharing abstract class LoggerSObjectHandler {
private Map<Id, SObject> triggerNewMap;
@TestVisible
private Map<Id, SObject> triggerOldMap;
private SObjectHandlerInput input;
protected SObjectHandlerInput input;
private List<LoggerPlugin__mdt> pluginConfigurations = new List<LoggerPlugin__mdt>();
private List<LoggerSObjectHandlerPlugin> executedApexPlugins = new List<LoggerSObjectHandlerPlugin>();

Expand All @@ -34,6 +34,7 @@ public without sharing abstract class LoggerSObjectHandler {
this.triggerOldMap = Trigger.oldMap;

this.queryPluginConfigurations();
this.createSObjectHandlerInput();
}

/**
Expand Down Expand Up @@ -73,8 +74,6 @@ public without sharing abstract class LoggerSObjectHandler {
return;
}

this.createSObjectHandlerInput();

switch on this.input.triggerOperationType {
when BEFORE_INSERT {
this.executeBeforeInsert(this.input.triggerNew);
Expand Down Expand Up @@ -143,10 +142,10 @@ public without sharing abstract class LoggerSObjectHandler {

// Trigger variables for Apex Developers
input.sobjectType = this.getSObjectType();
input.triggerOperationType = triggerOperationType;
input.triggerNew = triggerNew;
input.triggerNewMap = triggerNewMap;
input.triggerOldMap = triggerOldMap;
input.triggerOperationType = this.triggerOperationType;
input.triggerNew = this.triggerNew;
input.triggerNewMap = this.triggerNewMap;
input.triggerOldMap = this.triggerOldMap;

// Additional invocable variables for Flow Builders (and Apex Developers too, if they want to use them)
input.sobjectTypeName = this.getSObjectType().getDescribe().getName();
Expand Down Expand Up @@ -192,6 +191,7 @@ public without sharing abstract class LoggerSObjectHandler {
String.join(orderByConditions, ', ')
};
String query = String.format(queryTemplate, queryInputs);

this.pluginConfigurations = (List<LoggerPlugin__mdt>) Database.query(query);

if (System.Test.isRunningTest() == true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,13 @@ public without sharing class LoggerSettingsController {
saveMethodNames.add(saveMethod.name());
}

List<String> additionalSaveMethods = LoggerParameter.getStringList('AdditionalSaveMethods', null);
if (additionalSaveMethods != null) {
saveMethodNames.addAll(additionalSaveMethods);
List<LoggerParameter__mdt> potentiallyMatchingParameters = [
SELECT Id, Value__c
FROM LoggerParameter__mdt
WHERE DeveloperName LIKE 'AdditionalSaveMethods%'
];
for (LoggerParameter__mdt matchingAdditionalParameter : potentiallyMatchingParameters) {
saveMethodNames.add(matchingAdditionalParameter.Value__c);
}
saveMethodNames.sort();
for (String saveMethodName : saveMethodNames) {
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 @@ -2583,7 +2583,7 @@ global with sharing class Logger {
// This gives us a chance to run the handler class & handler plugins before insert,
// allowing the plugins to make further changes to the `LogEntryEvent__e` records
// So, execute the handler, which internally then executes any plugins
new LogEntryEventHandler().executeBeforeInsert(logEntryEvents);
new LogEntryEventHandler(logEntryEvents, TriggerOperation.BEFORE_INSERT).execute();

// Now that the plugins have run, double check to make sure that saving should still happen
if (getBufferSize() == 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
public without sharing class LogEntryArchiveBuilder extends LoggerSObjectHandlerPlugin {
@TestVisible
private static LogEntryEvent__e mockEvent;
@TestVisible
private static List<LogEntryArchive__b> bigObjectsToInsert = new List<LogEntryArchive__b>();

public override void execute(LoggerPlugin__mdt configuration, LoggerSObjectHandler.SObjectHandlerInput input) {
if (Logger.getUserSettings().DefaultSaveMethod__c != 'BIG_OBJECT') {
return;
}

List<LogEntryEvent__e> logEntryEvents = (List<LogEntryEvent__e>) input.triggerNew;
for (LogEntryEvent__e logEntryEvent : logEntryEvents) {
bigObjectsToInsert.add(this.getLogEntryArchive(logEntryEvent));
}
if (!Test.isRunningTest()) {
Database.insertImmediate(bigObjectsToInsert);
bigObjectsToInsert.clear();
}
Logger.flushBuffer();
}

public LogEntryArchive__b getLogEntryArchive(LogEntryEvent__e logEntryEvent) {
return new LogEntryArchive__b(
ApiVersion__c = logEntryEvent.ApiVersion__c,
DatabaseResultCollectionType__c = logEntryEvent.DatabaseResultCollectionType__c,
DatabaseResultJson__c = logEntryEvent.DatabaseResultJson__c,
DatabaseResultType__c = logEntryEvent.DatabaseResultType__c,
ExceptionMessage__c = logEntryEvent.ExceptionMessage__c,
ExceptionStackTrace__c = logEntryEvent.ExceptionStackTrace__c,
ExceptionType__c = logEntryEvent.ExceptionType__c,
LimitsAggregateQueriesMax__c = logEntryEvent.LimitsAggregateQueriesMax__c,
LimitsAggregateQueriesUsed__c = logEntryEvent.LimitsAggregateQueriesUsed__c,
LimitsAsyncCallsMax__c = logEntryEvent.LimitsAsyncCallsMax__c,
LimitsAsyncCallsUsed__c = logEntryEvent.LimitsAsyncCallsUsed__c,
LimitsCalloutsUsed__c = logEntryEvent.LimitsCalloutsUsed__c,
LimitsCpuTimeMax__c = logEntryEvent.LimitsCpuTimeMax__c,
LimitsCpuTimeUsed__c = logEntryEvent.LimitsCpuTimeUsed__c,
LimitsDmlRowsMax__c = logEntryEvent.LimitsDmlRowsMax__c,
LimitsDmlRowsUsed__c = logEntryEvent.LimitsDmlRowsUsed__c,
LimitsDmlStatementsMax__c = logEntryEvent.LimitsDmlStatementsMax__c,
LimitsDmlStatementsUsed__c = logEntryEvent.LimitsDmlStatementsUsed__c,
LimitsEmailInvocationsMax__c = logEntryEvent.LimitsEmailInvocationsMax__c,
LimitsEmailInvocationsUsed__c = logEntryEvent.LimitsEmailInvocationsUsed__c,
LimitsFutureCallsMax__c = logEntryEvent.LimitsFutureCallsMax__c,
LimitsFutureCallsUsed__c = logEntryEvent.LimitsFutureCallsUsed__c,
LimitsHeapSizeMax__c = logEntryEvent.LimitsHeapSizeMax__c,
LimitsHeapSizeUsed__c = logEntryEvent.LimitsHeapSizeUsed__c,
LimitsMobilePushApexCallsMax__c = logEntryEvent.LimitsMobilePushApexCallsMax__c,
LimitsMobilePushApexCallsUsed__c = logEntryEvent.LimitsMobilePushApexCallsUsed__c,
LimitsQueueableJobsMax__c = logEntryEvent.LimitsQueueableJobsMax__c,
LimitsQueueableJobsUsed__c = logEntryEvent.LimitsQueueableJobsUsed__c,
LimitsSoqlQueriesMax__c = logEntryEvent.LimitsSoqlQueriesMax__c,
LimitsSoqlQueriesUsed__c = logEntryEvent.LimitsSoqlQueriesUsed__c,
LimitsSoqlQueryLocatorRowsMax__c = logEntryEvent.LimitsSoqlQueryLocatorRowsMax__c,
LimitsSoqlQueryLocatorRowsUsed__c = logEntryEvent.LimitsSoqlQueryLocatorRowsUsed__c,
LimitsSoqlQueryRowsMax__c = logEntryEvent.LimitsSoqlQueryRowsMax__c,
LimitsSoqlQueryRowsUsed__c = logEntryEvent.LimitsSoqlQueryRowsUsed__c,
LimitsSoslSearchesMax__c = logEntryEvent.LimitsSoslSearchesMax__c,
LimitsSoslSearchesUsed__c = logEntryEvent.LimitsSoslSearchesUsed__c,
Locale__c = logEntryEvent.Locale__c,
LoggedBy__c = UserInfo.getUserId(),
LoggedByString__c = UserInfo.getUserId(),
LoggedByUsername__c = logEntryEvent.LoggedByUsername__c,
LoggingLevel__c = logEntryEvent.LoggingLevel__c,
LoggingLevelOrdinal__c = logEntryEvent.LoggingLevelOrdinal__c,
LoginApplication__c = logEntryEvent.LoginApplication__c,
LoginBrowser__c = logEntryEvent.LoginBrowser__c,
LoginHistoryId__c = logEntryEvent.LoginHistoryId__c,
LoginPlatform__c = logEntryEvent.LoginPlatform__c,
LoginType__c = logEntryEvent.LoginType__c,
LogoutUrl__c = logEntryEvent.LogoutUrl__c,
Message__c = logEntryEvent.Message__c,
NetworkId__c = logEntryEvent.NetworkId__c,
NetworkLoginUrl__c = logEntryEvent.NetworkLoginUrl__c,
NetworkLogoutUrl__c = logEntryEvent.NetworkLogoutUrl__c,
NetworkSelfRegistrationUrl__c = logEntryEvent.NetworkSelfRegistrationUrl__c,
NetworkUrlPathPrefix__c = logEntryEvent.NetworkUrlPathPrefix__c,
OrganizationDomainUrl__c = logEntryEvent.OrganizationDomainUrl__c,
OrganizationEnvironmentType__c = logEntryEvent.OrganizationEnvironmentType__c,
OrganizationId__c = logEntryEvent.OrganizationId__c,
OrganizationInstanceName__c = logEntryEvent.OrganizationInstanceName__c,
OrganizationName__c = logEntryEvent.OrganizationName__c,
OrganizationNamespacePrefix__c = logEntryEvent.OrganizationNamespacePrefix__c,
OrganizationType__c = logEntryEvent.OrganizationType__c,
OriginLocation__c = logEntryEvent.OriginLocation__c,
OriginType__c = logEntryEvent.OriginType__c,
ParentLogTransactionId__c = logEntryEvent.ParentLogTransactionId__c,
ProfileId__c = logEntryEvent.ProfileId__c,
ProfileName__c = logEntryEvent.ProfileName__c,
RecordCollectionType__c = logEntryEvent.RecordCollectionType__c,
RecordId__c = logEntryEvent.RecordId__c,
RecordJson__c = logEntryEvent.RecordJson__c,
RecordSObjectClassification__c = logEntryEvent.RecordSObjectClassification__c,
RecordSObjectType__c = logEntryEvent.RecordSObjectType__c,
RecordSObjectTypeNamespace__c = logEntryEvent.RecordSObjectTypeNamespace__c,
SessionId__c = logEntryEvent.SessionId__c,
SessionSecurityLevel__c = logEntryEvent.SessionSecurityLevel__c,
SessionType__c = logEntryEvent.SessionType__c,
SourceIp__c = logEntryEvent.SourceIp__c,
StackTrace__c = logEntryEvent.StackTrace__c,
SystemMode__c = logEntryEvent.SystemMode__c,
ThemeDisplayed__c = logEntryEvent.ThemeDisplayed__c,
Timestamp__c = logEntryEvent.Timestamp__c,
TimestampString__c = logEntryEvent.TimestampString__c,
TimeZoneId__c = logEntryEvent.TimeZoneId__c,
Topics__c = logEntryEvent.Topics__c,
TransactionEntryNumber__c = logEntryEvent.TransactionEntryNumber__c,
TransactionId__c = logEntryEvent.TransactionId__c,
TriggerOperationType__c = logEntryEvent.TriggerOperationType__c,
TriggerSObjectType__c = logEntryEvent.TriggerSObjectType__c,
UserLicenseDefinitionKey__c = logEntryEvent.UserLicenseDefinitionKey__c,
UserLicenseName__c = logEntryEvent.UserLicenseName__c,
UserLoggingLevel__c = logEntryEvent.UserLoggingLevel__c,
UserLoggingLevelOrdinal__c = logEntryEvent.UserLoggingLevelOrdinal__c,
UserRoleId__c = logEntryEvent.UserRoleId__c,
UserRoleName__c = logEntryEvent.UserRoleName__c,
UserType__c = logEntryEvent.UserType__c
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>54.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
<label>Additional Save Methods</label>
<label>Additional Save Methods: Big Object</label>
<protected>true</protected>
<values>
<field>Description__c</field>
<value
xsi:type="xsd:string"
>An optional array of additional save methods to display when configuring the field LoggerSettings__c.DefaultSaveMethod__c in the LWC loggerSettings. When not configured, only the enum values of Logger.SaveMethod are used. This can be used to add new save methods that are provided by plugins.</value>
</values>
<values>
<field>Value__c</field>
<value xsi:type="xsd:string">BIG_OBJECT</value>
</values>
</CustomMetadata>
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
</values>
<values>
<field>PluginApiName__c</field>
<value xsi:type="xsd:string">TODO</value>
<value xsi:type="xsd:string">LogEntryArchiveBuilder</value>
</values>
<values>
<field>PluginType__c</field>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<deploymentStatus>InDevelopment</deploymentStatus>
<description>Big Object representation of Logger data. Can be used as a standalone archive, or in conjunction with platform events and the existing Log__c custom object.</description>
<label>Log Archive</label>
<pluralLabel>Log Archives</pluralLabel>
</CustomObject>
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>ApiVersion__c</fullName>
<externalId>false</externalId>
<isFilteringDisabled>false</isFilteringDisabled>
<isNameField>false</isNameField>
<isSortingDisabled>false</isSortingDisabled>
<label>API Version</label>
<length>5</length>
<required>false</required>
<type>Text</type>
<unique>false</unique>
</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>DatabaseResultCollectionType__c</fullName>
<externalId>false</externalId>
<isFilteringDisabled>false</isFilteringDisabled>
<isNameField>false</isNameField>
<isSortingDisabled>false</isSortingDisabled>
<label>Database Result Collection Type</label>
<length>255</length>
<required>false</required>
<type>Text</type>
<unique>false</unique>
</CustomField>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>DatabaseResultJson__c</fullName>
<externalId>false</externalId>
<isFilteringDisabled>false</isFilteringDisabled>
<isNameField>false</isNameField>
<isSortingDisabled>false</isSortingDisabled>
<label>Database Result JSON</label>
<length>131072</length>
<type>LongTextArea</type>
<visibleLines>8</visibleLines>
</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>DatabaseResultType__c</fullName>
<externalId>false</externalId>
<isFilteringDisabled>false</isFilteringDisabled>
<isNameField>false</isNameField>
<isSortingDisabled>false</isSortingDisabled>
<label>Database Result Type</label>
<length>255</length>
<required>false</required>
<type>Text</type>
<unique>false</unique>
</CustomField>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>ExceptionMessage__c</fullName>
<externalId>false</externalId>
<isFilteringDisabled>false</isFilteringDisabled>
<isNameField>false</isNameField>
<isSortingDisabled>false</isSortingDisabled>
<label>Exception Message</label>
<length>131072</length>
<type>LongTextArea</type>
<visibleLines>8</visibleLines>
</CustomField>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>ExceptionStackTrace__c</fullName>
<externalId>false</externalId>
<isFilteringDisabled>false</isFilteringDisabled>
<isNameField>false</isNameField>
<isSortingDisabled>false</isSortingDisabled>
<label>Exception Stack Trace</label>
<length>131072</length>
<type>LongTextArea</type>
<visibleLines>8</visibleLines>
</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>ExceptionType__c</fullName>
<externalId>false</externalId>
<isFilteringDisabled>false</isFilteringDisabled>
<isNameField>false</isNameField>
<isSortingDisabled>false</isSortingDisabled>
<label>Exception Type</label>
<length>255</length>
<required>false</required>
<type>Text</type>
<unique>false</unique>
</CustomField>
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>LimitsAggregateQueriesMax__c</fullName>
<externalId>false</externalId>
<isFilteringDisabled>false</isFilteringDisabled>
<isNameField>false</isNameField>
<isSortingDisabled>false</isSortingDisabled>
<label>Aggregate Queries Max</label>
<precision>10</precision>
<required>false</required>
<scale>0</scale>
<type>Number</type>
<unique>false</unique>
</CustomField>
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>LimitsAggregateQueriesUsed__c</fullName>
<externalId>false</externalId>
<isFilteringDisabled>false</isFilteringDisabled>
<isNameField>false</isNameField>
<isSortingDisabled>false</isSortingDisabled>
<label>Aggregate Queries Used</label>
<precision>10</precision>
<required>false</required>
<scale>0</scale>
<type>Number</type>
<unique>false</unique>
</CustomField>
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>LimitsAggregateQueryMax__c</fullName>
<externalId>false</externalId>
<isFilteringDisabled>false</isFilteringDisabled>
<isNameField>false</isNameField>
<isSortingDisabled>false</isSortingDisabled>
<label>Limits AggregateQueryMax_</label>
<precision>18</precision>
<required>false</required>
<scale>0</scale>
<type>Number</type>
<unique>false</unique>
</CustomField>
Loading

0 comments on commit b6251fc

Please sign in to comment.