Skip to content

Commit

Permalink
V1.2.38 - Rollup Goes On a Diet (#148)
Browse files Browse the repository at this point in the history
* Started using `unpackagedMetadata` property for apex-rollup base package so that extra-tests folder is included by default in code coverage calculation for package creation

* Updating custom logger plugin to ensure log message doesn't overflow platform event / RollupLogEntry__c.Message__c field

* Fixes #146 by going further down the rollup orchestrator/conductor path - the 'outer' rollup (previously referred to as the batchRollup - deprecating that term so that it's clear when a rollup is batched versus queued versus run sync) now 'conducts' the inner rollups by storing the calcItems and oldCalcItems map. This should drastically reduce memory consumption by basically eliminating how many List<SObject> copies are being passed around in memory; whereas previously, the more CMDT/Rollup invocations you used, the more Lists were stored, now the outer rollup condenses that information into one place.

* Packaging script updates to restore its functionality following the plugins release

* Updating Rollup Custom Logger to include Error Would Have Been Thrown custom field

* Further work on the Rollup side to accommodate the rollup custom logger plugin changes for new Error Would Have Been Thrown field (thanks to @jongpie for the review on this one!)
  • Loading branch information
jamessimone authored Jul 30, 2021
1 parent ecd38f9 commit e65af41
Show file tree
Hide file tree
Showing 23 changed files with 444 additions and 322 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ Create fast, scalable custom rollups driven by Custom Metadata in your Salesforc

### Package deployment options

<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008SguzAAC">
<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008SgySAAS">
<img alt="Deploy to Salesforce"
src="./media/deploy-package-to-prod.png">
</a>

<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008SguzAAC">
<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008SgySAAS">
<img alt="Deploy to Salesforce Sandbox"
src="./media/deploy-package-to-sandbox.png">
</a>
Expand Down
2 changes: 1 addition & 1 deletion extra-tests/classes/InvocableDrivenTests.cls
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private class InvocableDrivenTests {
System.assertEquals(today.addDays(-2), reparentAccount.DateField__c);
System.assertEquals(3, reparentAccount.NumberOfEmployees, 'Second account should properly reflect reparented record for number of employees');
System.assertEquals(one.Description + ', ' + three.Description, reparentAccount.Description, 'Second account should have only reparented case description');
System.assertEquals(one.Subject, reparentAccount.Name, 'Second account name field should reflect last subject');
System.assertEquals(2, reparentAccount.AnnualRevenue, 'Second account sum field should include updated amount');
System.assertEquals(one.Subject, reparentAccount.Name, 'Second account name field should reflect last subject');
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apex-rollup",
"version": "1.2.37.0",
"version": "1.2.38.0",
"description": "Fast, configurable, elastically scaling custom rollup solution. Apex Invocable action, one-liner Apex trigger/CMDT-driven logic, and scheduled Apex-ready.",
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions plugins/CustomObjectRollupLogger/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Custom Object Rollup Logger

<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008SgufAAC">
<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008SgxPAAS">
<img alt="Deploy to Salesforce"
src="../../media/deploy-package-to-prod.png">
</a>

<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008SgufAAC">
<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008SgxPAAS">
<img alt="Deploy to Salesforce Sandbox"
src="../../media/deploy-package-to-sandbox.png">
</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
public class RollupCustomObjectLogger extends RollupLogger {
private final List<RollupLogEvent__e> rollupLogEvents = new List<RollupLogEvent__e>();
private final Database.DMLOptions truncatedAllowedOptions;

public RollupCustomObjectLogger() {
super();
this.truncatedAllowedOptions = new Database.DMLOptions();
this.truncatedAllowedOptions.AllowFieldTruncation = true;
}

public override void log(String logString, LoggingLevel logLevel) {
this.rollupLogEvents.add(new RollupLogEvent__e(
RollupLogEvent__e logEvent = new RollupLogEvent__e(
LoggingLevel__c = logLevel.name(),
LoggedBy__c = UserInfo.getUserId(),
Message__c = logString,
TransactionId__c = Request.getCurrent().getRequestId()
));
);
logEvent.setOptions(this.truncatedAllowedOptions);
this.rollupLogEvents.add(logEvent);
}

public override void log(String logString, Object logObject, LoggingLevel logLevel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ private class RollupCustomObjectLoggerTests {
Test.stopTest();

List<RollupLog__c> rollupLogs = [
SELECT Id, NumberOfLogEntries__c, TransactionId__c, (SELECT Message__c, LoggingLevel__c FROM RollupLogEntry__r)
SELECT Id, NumberOfLogEntries__c, TransactionId__c, ErrorWouldHaveBeenThrown__c, (SELECT Message__c, LoggingLevel__c FROM RollupLogEntry__r)
FROM RollupLog__c
];
System.assertEquals(1, rollupLogs.size(), 'Parent-level rollup log should have been created');
RollupLog__c firstEntry = rollupLogs[0];
System.assertNotEquals(null, firstEntry.TransactionId__c, 'Transaction Id should have been assigned');
System.assertEquals(true, firstEntry.ErrorWouldHaveBeenThrown__c, 'ERROR level log message was created, this field should be flagged');

// Rollup Log Entries
System.assertEquals(2, firstEntry.RollupLogEntry__r.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ public class RollupLogEventHandler {
Map<String, RollupLog__c> transactionIdToLogs = new Map<String, RollupLog__c>();

for (RollupLogEvent__e logEvent : logEvents) {
RollupLog__c rollupLog = new RollupLog__c(TransactionId__c = logEvent.TransactionId__c, LoggedBy__c = Id.valueOf(logEvent.LoggedBy__c));
RollupLog__c rollupLog = new RollupLog__c(
ErrorWouldHaveBeenThrown__c = logEvent.LoggingLevel__c == LoggingLevel.ERROR.name(),
LoggedBy__c = Id.valueOf(logEvent.LoggedBy__c),
TransactionId__c = logEvent.TransactionId__c
);
transactionIdToLogs.put(logEvent.TransactionId__c, rollupLog);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<behavior>Readonly</behavior>
<field>NumberOfLogEntries__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>ErrorWouldHaveBeenThrown__c</field>
</layoutItems>
</layoutColumns>
<style>TwoColumnsTopToBottom</style>
</layoutSections>
Expand All @@ -44,6 +48,10 @@
<behavior>Readonly</behavior>
<field>LastModifiedById</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>TransactionId__c</field>
</layoutItems>
</layoutColumns>
<style>TwoColumnsTopToBottom</style>
</layoutSections>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
<type>AutoNumber</type>
</nameField>
<pluralLabel>Rollup Logs</pluralLabel>
<searchLayouts/>
<searchLayouts></searchLayouts>
<sharingModel>ReadWrite</sharingModel>
<visibility>Public</visibility>
</CustomObject>
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>ErrorWouldHaveBeenThrown__c</fullName>
<defaultValue>false</defaultValue>
<description>If Rollup logs an otherwise fatal exception (with LoggingLevel.ERROR), this field is checked off</description>
<externalId>false</externalId>
<inlineHelpText>If Rollup logs an otherwise fatal exception (with LoggingLevel.ERROR), this field is checked off</inlineHelpText>
<label>Error Would Have Been Thrown</label>
<trackHistory>false</trackHistory>
<trackTrending>false</trackTrending>
<type>Checkbox</type>
</CustomField>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>TransactionId__c</fullName>
<caseSensitive>false</caseSensitive>
Expand All @@ -10,4 +10,4 @@
<trackTrending>false</trackTrending>
<type>Text</type>
<unique>true</unique>
</CustomField>
</CustomField>
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
<description>Grants permission to Rollup Log information</description>
<fieldPermissions>
<editable>false</editable>
<field>RollupLog__c.ErrorWouldHaveBeenThrown__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>RollupLogEntry__c.Message__c</field>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<Profile xmlns="http://soap.sforce.com/2006/04/metadata">
<fieldPermissions>
<editable>false</editable>
<field>RollupLog__c.ErrorWouldHaveBeenThrown__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>true</editable>
<field>RollupLog__c.LoggedBy__c</field>
Expand Down
Loading

0 comments on commit e65af41

Please sign in to comment.