Skip to content

Commit

Permalink
Added the ability to log Flow record collections (#171)
Browse files Browse the repository at this point in the history
* Refactored FlowLogEntry and FlowRecordLogEntry to use new FlowLogger class for shared logic

* Added FlowCollectionLogEntry class

* Updated docs

* Small bugfix for dealing with List<SObject> & SObjectType in LogEntryEventBuilder

* Added a bit more Flow details to README.md

* Bumped package version & promoted new package version
  • Loading branch information
jongpie authored Jun 22, 2021
1 parent dae9b86 commit a9409ac
Show file tree
Hide file tree
Showing 31 changed files with 755 additions and 122 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@ name: Deployment

on:
push:
branches:
- main
paths-ignore:
- 'content/**'
- 'docs/**'
- 'examples/**'
- 'packages/**'
- '.forceignore'
- '.gitignore'
- '.prettierignore'
- '.prettierrc'
- 'Contributing.md'
- 'LICENSE'
- 'package.json'
- 'README.md'
- './**/README.md'
- 'sfdx-project.json'
pull_request:
types: [opened, edited, synchronize, reopened]
paths-ignore:
- 'content/**'
- 'docs/**'
Expand Down
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Designed for Salesforce admins, developers & architects. A robust logger for Apex, Flow, Process Builder & Integrations.

[![Install Unlocked Package](./content/btn-install-unlocked-package.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000027FMrQAM)
[![Install Unlocked Package](./content/btn-install-unlocked-package.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000027FN6QAM)
[![Install Managed Package](./content/btn-install-managed-package.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000027FMhQAM)
[![Deploy Unpackaged Metadata](./content/btn-deploy-unpackaged-metadata.png)](https://githubsfdeploy.herokuapp.com/?owner=jongpie&repo=NebulaLogger&ref=main)
[![View Documentation](./content/btn-view-documentation.png)](https://jongpie.github.io/NebulaLogger/)
Expand Down Expand Up @@ -174,7 +174,7 @@ This generates 1 consolidated `Log__c`, containing `LogEntry__c` records from bo

---

## Advanced Features for Apex Developers
## Features for Apex Developers

Within Apex, there are several different methods that you can use that provide greater control over the logging system.

Expand Down Expand Up @@ -348,6 +348,19 @@ For more details, check out the `LogMessage` class [documentation](https://jongp

---

## Features for Flow Builders

Within Flow (and Process Builder), there are 4 invocable actions that you can use to leverage Nebula Logger

1. 'Add Log Entry' - uses the class `FlowLogEntry` to add a log entry with a specified message
2. 'Add Log Entry for an SObject Record' - uses the class `FlowRecordLogEntry` to add a log entry with a specified message for a particular SObject record
3. 'Add Log Entry for an SObject Record Collection' - uses the class `FlowCollectionLogEntry` to add a log entry with a specified message for an SObject record collection
4. 'Save Log' - uses the class `Logger` to save any pending logs

![Flow Builder: Logging Invocable Actions](./content/flow-builder-logging-invocable-actions.png)

---

## Log Management

### Logger Console App
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ layout: default

## Logger Engine

### [FlowCollectionLogEntry](logger-engine/FlowCollectionLogEntry)

Handles adding new log entries in Flow for a particular `SObject` record collection

### [FlowLogEntry](logger-engine/FlowLogEntry)

Handles adding new log entries in Flow

### [FlowLogger](logger-engine/FlowLogger)

Handles some common logic used by `FlowLogEntry`, `FlowRecordLogEntry` and `FlowCollectionLogEntry`

### [FlowRecordLogEntry](logger-engine/FlowRecordLogEntry)

Handles adding new log entries in Flow for a particular `SObject` record
Expand Down
79 changes: 79 additions & 0 deletions docs/logger-engine/FlowCollectionLogEntry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
layout: default
---

## FlowCollectionLogEntry class

Handles adding new log entries in Flow for a particular `SObject` record collection

### Related

[FlowLogEntry](FlowLogEntry)

[FlowRecordLogEntry](FlowRecordLogEntry)

[FlowLogger](FlowLogger)

[Logger](Logger)

[LogEntryEventBuilder](LogEntryEventBuilder)

---

### Properties

#### `faultMessage``String`

Optionally log a Flow fault error message

#### `flowName``String`

The name of the Flow creating the log entry. Due to Salesforce limitations, this cannot be automatically determined

#### `loggingLevelName``String`

Optionally specify a logging level - the default is 'DEBUG'

#### `message``String`

The message to log

#### `records``List<SObject>`

The records to relate to this log entry - the records' JSON is automatically added to the log entry

#### `saveLog``Boolean`

Optionally choose to save any pending log entries

#### `timestamp``DateTime`

#### `topics``List<String>`

Optionally provide a list of topics to dynamically assign to the log entry

---

### Methods

#### `addFlowCollectionEntries(List<FlowCollectionLogEntry> flowCollectionLogEntries)``List<String>`

addFlowRecordEntries description

##### Parameters

| Param | Description |
| ---------------------- | ------------------------------------------------ |
| `flowRecordLogEntries` | The list of FlowRecordLogEntry instances to save |

##### Return

**Type**

List<String>

**Description**

The current transaction's ID (based on `Logger.getTransactionId()`)

---
6 changes: 6 additions & 0 deletions docs/logger-engine/FlowLogEntry.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Handles adding new log entries in Flow

[FlowRecordLogEntry](FlowRecordLogEntry)

[FlowCollectionLogEntry](FlowCollectionLogEntry)

[FlowLogger](FlowLogger)

[Logger](Logger)

[LogEntryEventBuilder](LogEntryEventBuilder)
Expand Down Expand Up @@ -42,6 +46,8 @@ Optionally relate the log entry to a particular record ID

Optionally choose to save any pending log entries.

#### `timestamp``DateTime`

#### `topics``List<String>`

Optionally provide a list of topics to dynamically assign to the log entry
Expand Down
57 changes: 57 additions & 0 deletions docs/logger-engine/FlowLogger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
layout: default
---

## FlowLogger class

Handles some common logic used by `FlowLogEntry`, `FlowRecordLogEntry` and `FlowCollectionLogEntry`

### Related

[FlowLogEntry](FlowLogEntry)

[FlowRecordLogEntry](FlowRecordLogEntry)

[FlowCollectionLogEntry](FlowCollectionLogEntry)

[Logger](Logger)

[LogEntryEventBuilder](LogEntryEventBuilder)

---

### Methods

#### `addEntries(List<LogEntry> flowEntries)``List<String>`

---

### Inner Classes

#### FlowLogger.LogEntry class

---

##### Properties

###### `faultMessage``String`

###### `flowName``String`

###### `loggingLevelName``String`

###### `message``String`

###### `saveLog``Boolean`

###### `timestamp``DateTime`

###### `topics``List<String>`

---

##### Methods

###### `addToLoggerBuffer()``LogEntryEventBuilder`

---
6 changes: 6 additions & 0 deletions docs/logger-engine/FlowRecordLogEntry.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Handles adding new log entries in Flow for a particular `SObject` record

[FlowLogEntry](FlowLogEntry)

[FlowCollectionLogEntry](FlowCollectionLogEntry)

[FlowLogger](FlowLogger)

[Logger](Logger)

[LogEntryEventBuilder](LogEntryEventBuilder)
Expand Down Expand Up @@ -42,6 +46,8 @@ The record to relate to this log entry - the record's JSON is automatically adde

Optionally choose to save any pending log entries

#### `timestamp``DateTime`

#### `topics``List<String>`

Optionally provide a list of topics to dynamically assign to the log entry
Expand Down
6 changes: 2 additions & 4 deletions nebula-logger/main/log-management/classes/LogHandler.cls
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,11 @@ public without sharing class LogHandler extends LoggerSObjectHandler {
releaseCycle = 'Non-Preview Instance';
} else if (previewInstances.contains(ORGANIZATION.InstanceName)) {
releaseCycle = 'Preview Instance';
} else {
// Use 'Unknown' as the default for private instances and situations where the hardcoded sets above are missing some values
releaseCycle = 'Unknown';
}

for (Log__c log : this.logs) {
log.OrganizationInstanceReleaseCycle__c = releaseCycle;
// Use 'Unknown' as the default for private instances and situations where the hardcoded sets above are missing some values
log.OrganizationInstanceReleaseCycle__c = String.isNotBlank(releaseCycle) ? releaseCycle : 'Unknown';
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ public with sharing class LogMassDeleteExtension {
* @return The PageReference of the previous page (based on `controller.cancel()`)
*/
public PageReference deleteSelectedLogs() {
try {
delete getDeletableLogs();
} catch (Exception ex) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, ex.getMessage()));
}
delete getDeletableLogs();

// The controller's method cancel() just returns the user to the previous page - it doesn't rollback any DML statements (like the delete above)
return this.controller.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
<application>LoggerConsole</application>
<visible>true</visible>
</applicationVisibilities>
<classAccesses>
<apexClass>FlowCollectionLogEntry</apexClass>
<enabled>true</enabled>
</classAccesses>
<classAccesses>
<apexClass>FlowLogEntry</apexClass>
<enabled>true</enabled>
</classAccesses>
<classAccesses>
<apexClass>FlowLogger</apexClass>
<enabled>true</enabled>
</classAccesses>
<classAccesses>
<apexClass>FlowRecordLogEntry</apexClass>
<enabled>true</enabled>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
<classAccesses>
<apexClass>FlowCollectionLogEntry</apexClass>
<enabled>true</enabled>
</classAccesses>
<classAccesses>
<apexClass>FlowLogEntry</apexClass>
<enabled>true</enabled>
</classAccesses>
<classAccesses>
<apexClass>FlowLogger</apexClass>
<enabled>true</enabled>
</classAccesses>
<classAccesses>
<apexClass>FlowRecordLogEntry</apexClass>
<enabled>true</enabled>
Expand Down
16 changes: 16 additions & 0 deletions nebula-logger/main/log-management/profiles/Admin.profile-meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
<default>false</default>
<visible>true</visible>
</applicationVisibilities>
<classAccesses>
<apexClass>FlowCollectionLogEntry</apexClass>
<enabled>true</enabled>
</classAccesses>
<classAccesses>
<apexClass>FlowCollectionLogEntry_Tests</apexClass>
<enabled>true</enabled>
</classAccesses>
<classAccesses>
<apexClass>FlowLogEntry</apexClass>
<enabled>true</enabled>
Expand All @@ -13,6 +21,14 @@
<apexClass>FlowLogEntry_Tests</apexClass>
<enabled>true</enabled>
</classAccesses>
<classAccesses>
<apexClass>FlowLogger</apexClass>
<enabled>true</enabled>
</classAccesses>
<classAccesses>
<apexClass>FlowLogger_Tests</apexClass>
<enabled>true</enabled>
</classAccesses>
<classAccesses>
<apexClass>FlowRecordLogEntry</apexClass>
<enabled>true</enabled>
Expand Down
Loading

0 comments on commit a9409ac

Please sign in to comment.