Skip to content

Commit

Permalink
Add setRecord method to LogEntryEventBuilder for handling Set of Ids …
Browse files Browse the repository at this point in the history
…and List of Ids (#792)
  • Loading branch information
alanjaouen authored Nov 7, 2024
1 parent e58b02f commit 1b437ce
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 11 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 observability solution for Salesforce experts. Built 100% natively on the platform, and designed to work seamlessly with Apex, Lightning Components, Flow, OmniStudio, and integrations.

## Unlocked Package - v4.14.17
## Unlocked Package - v4.14.18

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

`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y0000015ocRQAQ`
`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y0000015ocbQAA`

`sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y0000015ocRQAQ`
`sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y0000015ocbQAA`

---

Expand Down
20 changes: 20 additions & 0 deletions docs/apex/Logger-Engine/LogEntryEventBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,26 @@ LogEntryEventBuilder

The same instance of `LogEntryEventBuilder`, useful for chaining methods

#### `setRecord(System.Iterable<Id> recordsIds)``LogEntryEventBuilder`

Sets the log entry event&apos;s record fields

##### Parameters

| Param | Description |
| ------------ | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `recordsIds` | The Set of `SObject` records ids related to the entry. Will be converted to list and the JSON of the list is automatically added to the entry |

##### Return

**Type**

LogEntryEventBuilder

**Description**

The same instance of `LogEntryEventBuilder`, useful for chaining methods

#### `setRecordId(Id recordId)``LogEntryEventBuilder`

Deprecated - use `setRecord(Id recordId)` instead
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,29 @@ global with sharing class LogEntryEventBuilder {
return this;
}

/**
* @description Sets the log entry event's record fields
* @param recordsIds The Set of `SObject` records ids related to the entry. Will be converted to list and the JSON of the list is automatically added to the entry
* @return The same instance of `LogEntryEventBuilder`, useful for chaining methods
*/
global LogEntryEventBuilder setRecord(System.Iterable<Id> recordsIds) {
if (this.shouldSave() == false) {
return this;
}

List<SObject> records;
if (recordsIds != null) {
records = new List<SObject>();
for (Id recordId : recordsIds) {
SObject record = recordId.getSObjectType().newSObject();
record.Id = recordId;
records.add(record);
}
}

return this.setRecord(records);
}

/**
* @description Sets the log entry event's HTTP Request fields
* @param request The instance of `HttpRequest` to log
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.14.17';
private static final String CURRENT_VERSION_NUMBER = 'v4.14.18';
private static final System.LoggingLevel FALLBACK_LOGGING_LEVEL = System.LoggingLevel.DEBUG;
private static final List<LogEntryEventBuilder> LOG_ENTRIES_BUFFER = new List<LogEntryEventBuilder>();
private static final String MISSING_SCENARIO_ERROR_MESSAGE = 'No logger scenario specified. A scenario is required for logging in this org.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import LoggerServiceTaskQueue from './loggerServiceTaskQueue';
import getSettings from '@salesforce/apex/ComponentLogger.getSettings';
import saveComponentLogEntries from '@salesforce/apex/ComponentLogger.saveComponentLogEntries';

const CURRENT_VERSION_NUMBER = 'v4.14.17';
const CURRENT_VERSION_NUMBER = 'v4.14.18';

const CONSOLE_OUTPUT_CONFIG = {
messagePrefix: `%c Nebula Logger ${CURRENT_VERSION_NUMBER} `,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ private class LogEntryEventBuilder_Tests {
System.Assert.isNull(builder.setRecord(System.UserInfo.getUserId()).getLogEntryEvent());
System.Assert.isNull(builder.setRecord(new Schema.User(Id = System.UserInfo.getUserId())).getLogEntryEvent());
System.Assert.isNull(builder.setRecord(new List<Schema.User>{ new Schema.User(Id = System.UserInfo.getUserId()) }).getLogEntryEvent());
System.Assert.isNull(builder.setRecord(new Set<Id>{ System.UserInfo.getUserId() }).getLogEntryEvent());
System.Assert.isNull(builder.addTags(new List<String>{ 'tag-1', 'tag-2' }).getLogEntryEvent());
System.Assert.isNull(builder.parseStackTrace(new System.DmlException().getStackTraceString()).getLogEntryEvent());
}
Expand Down Expand Up @@ -1249,6 +1250,66 @@ private class LogEntryEventBuilder_Tests {
System.Assert.areEqual(Schema.User.SObjectType.getDescribe().getName(), builder.getLogEntryEvent().RecordSObjectType__c);
}

@IsTest
static void it_should_set_record_fields_for_iterable_ids_when_null() {
LogEntryEventBuilder builder = new LogEntryEventBuilder(getUserSettings(), System.LoggingLevel.INFO, true);
System.Assert.isNull(builder.getLogEntryEvent().RecordId__c);
System.Assert.isNull(builder.getLogEntryEvent().RecordJson__c);
System.Assert.isNull(builder.getLogEntryEvent().RecordSObjectClassification__c);
System.Assert.isNull(builder.getLogEntryEvent().RecordSObjectType__c);
System.Assert.isNull(builder.getLogEntryEvent().RecordSObjectTypeNamespace__c);

System.Iterable<Id> nullIterableIds = null;
builder.setRecord(nullIterableIds);

System.Assert.isNull(builder.getLogEntryEvent().RecordCollectionSize__c);
System.Assert.areEqual('List', builder.getLogEntryEvent().RecordCollectionType__c);
System.Assert.isNull(builder.getLogEntryEvent().RecordId__c);
System.Assert.areEqual('null', builder.getLogEntryEvent().RecordJson__c);
System.Assert.areEqual('Unknown', builder.getLogEntryEvent().RecordSObjectClassification__c);
System.Assert.areEqual('Unknown', builder.getLogEntryEvent().RecordSObjectType__c);
}

@IsTest
static void it_should_set_record_fields_for_list_of_id_records_when_populated() {
LogEntryEventBuilder builder = new LogEntryEventBuilder(getUserSettings(), System.LoggingLevel.INFO, true);
System.Assert.isNull(builder.getLogEntryEvent().RecordId__c);
System.Assert.isNull(builder.getLogEntryEvent().RecordJson__c);
System.Assert.isNull(builder.getLogEntryEvent().RecordSObjectClassification__c);
System.Assert.isNull(builder.getLogEntryEvent().RecordSObjectType__c);
System.Assert.isNull(builder.getLogEntryEvent().RecordSObjectTypeNamespace__c);

List<Id> userIdList = new List<Id>(new Map<Id, Schema.User>([SELECT Id, Name, Username, IsActive FROM User LIMIT 5]).keySet());
builder.setRecord(userIdList);

System.Assert.areEqual(userIdList.size(), builder.getLogEntryEvent().RecordCollectionSize__c);
System.Assert.areEqual('List', builder.getLogEntryEvent().RecordCollectionType__c);
System.Assert.isNull(builder.getLogEntryEvent().RecordId__c);
System.Assert.isNotNull(builder.getLogEntryEvent().RecordJson__c);
System.Assert.areEqual('Unknown', builder.getLogEntryEvent().RecordSObjectClassification__c);
System.Assert.areEqual('Unknown', builder.getLogEntryEvent().RecordSObjectType__c);
}

@IsTest
static void it_should_set_record_fields_for_set_of_id_records_when_populated() {
LogEntryEventBuilder builder = new LogEntryEventBuilder(getUserSettings(), System.LoggingLevel.INFO, true);
System.Assert.isNull(builder.getLogEntryEvent().RecordId__c);
System.Assert.isNull(builder.getLogEntryEvent().RecordJson__c);
System.Assert.isNull(builder.getLogEntryEvent().RecordSObjectClassification__c);
System.Assert.isNull(builder.getLogEntryEvent().RecordSObjectType__c);
System.Assert.isNull(builder.getLogEntryEvent().RecordSObjectTypeNamespace__c);

Set<Id> userIdSet = new Map<Id, Schema.User>([SELECT Id, Name, Username, IsActive FROM User LIMIT 5]).keySet();
builder.setRecord(userIdSet);

System.Assert.areEqual(userIdSet.size(), builder.getLogEntryEvent().RecordCollectionSize__c);
System.Assert.areEqual('List', builder.getLogEntryEvent().RecordCollectionType__c);
System.Assert.isNull(builder.getLogEntryEvent().RecordId__c);
System.Assert.isNotNull(builder.getLogEntryEvent().RecordJson__c);
System.Assert.areEqual('Unknown', builder.getLogEntryEvent().RecordSObjectClassification__c);
System.Assert.areEqual('Unknown', builder.getLogEntryEvent().RecordSObjectType__c);
}

@IsTest
static void it_should_skip_setting_http_request_fields_when_request_is_null() {
LogEntryEventBuilder builder = new LogEntryEventBuilder(getUserSettings(), System.LoggingLevel.INFO, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//------------------------------------------------------------------------------------------------//
// This file is part of the Nebula Logger project, released under the MIT License. //
// See LICENSE file or go to https://github.com/jongpie/NebulaLogger for full license details. //
//------------------------------------------------------------------------------------------------//

// This class intentionally does nothing - it's here to ensure that any references
// in Nebula Logger's codebase use `System.Iterable` instead of just `Iterable`
@SuppressWarnings('PMD.ApexDoc, PMD.EmptyStatementBlock')
public without sharing class Iterable {
}
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>61.0</apiVersion>
<status>Active</status>
</ApexClass>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nebula-logger",
"version": "4.14.17",
"version": "4.14.18",
"description": "The most robust logger for Salesforce. Works with Apex, Lightning Components, Flow, Process Builder & Integrations. Designed for Salesforce admins, developers & architects.",
"author": "Jonathan Gillespie",
"license": "MIT",
Expand Down
7 changes: 4 additions & 3 deletions sfdx-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"path": "./nebula-logger/core",
"definitionFile": "./config/scratch-orgs/base-scratch-def.json",
"scopeProfiles": true,
"versionNumber": "4.14.17.NEXT",
"versionName": "Improved JavaScript Console Output",
"versionDescription": "Added more details to the component log entry JSON that's printed using console statements. The stringified object now includes more details, such as the exception, tags, and scenario.",
"versionNumber": "4.14.18.NEXT",
"versionName": "Added setRecord() Overload for List<Id> and Set<Id> Parameters",
"versionDescription": "Added a new overload setRecord(System.Iterable<Id> recordsIds) in LogEntryEventBuilder to make it easy to log List<Id> and Set<Id>.",
"releaseNotesUrl": "https://github.com/jongpie/NebulaLogger/releases",
"unpackagedMetadata": {
"path": "./nebula-logger/extra-tests"
Expand Down Expand Up @@ -202,6 +202,7 @@
"Nebula Logger - [email protected]": "04t5Y0000015obxQAA",
"Nebula Logger - [email protected]": "04t5Y0000015ocHQAQ",
"Nebula Logger - [email protected]": "04t5Y0000015ocRQAQ",
"Nebula Logger - [email protected]()-overload-for-list<id>-and-set<id>-parameters": "04t5Y0000015ocbQAA",
"Nebula Logger - Core Plugin - Async Failure Additions": "0Ho5Y000000blO4SAI",
"Nebula Logger - Core Plugin - Async Failure [email protected]": "04t5Y0000015lhiQAA",
"Nebula Logger - Core Plugin - Async Failure [email protected]": "04t5Y0000015lhsQAA",
Expand Down

0 comments on commit 1b437ce

Please sign in to comment.