Skip to content

Commit 1b437ce

Browse files
authored
Add setRecord method to LogEntryEventBuilder for handling Set of Ids and List of Ids (#792)
1 parent e58b02f commit 1b437ce

10 files changed

Lines changed: 131 additions & 11 deletions

File tree

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
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.
77

8-
## Unlocked Package - v4.14.17
8+
## Unlocked Package - v4.14.18
99

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

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

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

1818
---
1919

docs/apex/Logger-Engine/LogEntryEventBuilder.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,26 @@ LogEntryEventBuilder
632632

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

635+
#### `setRecord(System.Iterable<Id> recordsIds)``LogEntryEventBuilder`
636+
637+
Sets the log entry event&apos;s record fields
638+
639+
##### Parameters
640+
641+
| Param | Description |
642+
| ------------ | --------------------------------------------------------------------------------------------------------------------------------------------- |
643+
| `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 |
644+
645+
##### Return
646+
647+
**Type**
648+
649+
LogEntryEventBuilder
650+
651+
**Description**
652+
653+
The same instance of `LogEntryEventBuilder`, useful for chaining methods
654+
635655
#### `setRecordId(Id recordId)``LogEntryEventBuilder`
636656

637657
Deprecated - use `setRecord(Id recordId)` instead

nebula-logger/core/main/logger-engine/classes/LogEntryEventBuilder.cls

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,29 @@ global with sharing class LogEntryEventBuilder {
462462
return this;
463463
}
464464

465+
/**
466+
* @description Sets the log entry event's record fields
467+
* @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
468+
* @return The same instance of `LogEntryEventBuilder`, useful for chaining methods
469+
*/
470+
global LogEntryEventBuilder setRecord(System.Iterable<Id> recordsIds) {
471+
if (this.shouldSave() == false) {
472+
return this;
473+
}
474+
475+
List<SObject> records;
476+
if (recordsIds != null) {
477+
records = new List<SObject>();
478+
for (Id recordId : recordsIds) {
479+
SObject record = recordId.getSObjectType().newSObject();
480+
record.Id = recordId;
481+
records.add(record);
482+
}
483+
}
484+
485+
return this.setRecord(records);
486+
}
487+
465488
/**
466489
* @description Sets the log entry event's HTTP Request fields
467490
* @param request The instance of `HttpRequest` to log

nebula-logger/core/main/logger-engine/classes/Logger.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
global with sharing class Logger {
1616
// There's no reliable way to get the version number dynamically in Apex
1717
@TestVisible
18-
private static final String CURRENT_VERSION_NUMBER = 'v4.14.17';
18+
private static final String CURRENT_VERSION_NUMBER = 'v4.14.18';
1919
private static final System.LoggingLevel FALLBACK_LOGGING_LEVEL = System.LoggingLevel.DEBUG;
2020
private static final List<LogEntryEventBuilder> LOG_ENTRIES_BUFFER = new List<LogEntryEventBuilder>();
2121
private static final String MISSING_SCENARIO_ERROR_MESSAGE = 'No logger scenario specified. A scenario is required for logging in this org.';

nebula-logger/core/main/logger-engine/lwc/logger/loggerService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import LoggerServiceTaskQueue from './loggerServiceTaskQueue';
1010
import getSettings from '@salesforce/apex/ComponentLogger.getSettings';
1111
import saveComponentLogEntries from '@salesforce/apex/ComponentLogger.saveComponentLogEntries';
1212

13-
const CURRENT_VERSION_NUMBER = 'v4.14.17';
13+
const CURRENT_VERSION_NUMBER = 'v4.14.18';
1414

1515
const CONSOLE_OUTPUT_CONFIG = {
1616
messagePrefix: `%c Nebula Logger ${CURRENT_VERSION_NUMBER} `,

nebula-logger/core/tests/logger-engine/classes/LogEntryEventBuilder_Tests.cls

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ private class LogEntryEventBuilder_Tests {
3535
System.Assert.isNull(builder.setRecord(System.UserInfo.getUserId()).getLogEntryEvent());
3636
System.Assert.isNull(builder.setRecord(new Schema.User(Id = System.UserInfo.getUserId())).getLogEntryEvent());
3737
System.Assert.isNull(builder.setRecord(new List<Schema.User>{ new Schema.User(Id = System.UserInfo.getUserId()) }).getLogEntryEvent());
38+
System.Assert.isNull(builder.setRecord(new Set<Id>{ System.UserInfo.getUserId() }).getLogEntryEvent());
3839
System.Assert.isNull(builder.addTags(new List<String>{ 'tag-1', 'tag-2' }).getLogEntryEvent());
3940
System.Assert.isNull(builder.parseStackTrace(new System.DmlException().getStackTraceString()).getLogEntryEvent());
4041
}
@@ -1249,6 +1250,66 @@ private class LogEntryEventBuilder_Tests {
12491250
System.Assert.areEqual(Schema.User.SObjectType.getDescribe().getName(), builder.getLogEntryEvent().RecordSObjectType__c);
12501251
}
12511252

1253+
@IsTest
1254+
static void it_should_set_record_fields_for_iterable_ids_when_null() {
1255+
LogEntryEventBuilder builder = new LogEntryEventBuilder(getUserSettings(), System.LoggingLevel.INFO, true);
1256+
System.Assert.isNull(builder.getLogEntryEvent().RecordId__c);
1257+
System.Assert.isNull(builder.getLogEntryEvent().RecordJson__c);
1258+
System.Assert.isNull(builder.getLogEntryEvent().RecordSObjectClassification__c);
1259+
System.Assert.isNull(builder.getLogEntryEvent().RecordSObjectType__c);
1260+
System.Assert.isNull(builder.getLogEntryEvent().RecordSObjectTypeNamespace__c);
1261+
1262+
System.Iterable<Id> nullIterableIds = null;
1263+
builder.setRecord(nullIterableIds);
1264+
1265+
System.Assert.isNull(builder.getLogEntryEvent().RecordCollectionSize__c);
1266+
System.Assert.areEqual('List', builder.getLogEntryEvent().RecordCollectionType__c);
1267+
System.Assert.isNull(builder.getLogEntryEvent().RecordId__c);
1268+
System.Assert.areEqual('null', builder.getLogEntryEvent().RecordJson__c);
1269+
System.Assert.areEqual('Unknown', builder.getLogEntryEvent().RecordSObjectClassification__c);
1270+
System.Assert.areEqual('Unknown', builder.getLogEntryEvent().RecordSObjectType__c);
1271+
}
1272+
1273+
@IsTest
1274+
static void it_should_set_record_fields_for_list_of_id_records_when_populated() {
1275+
LogEntryEventBuilder builder = new LogEntryEventBuilder(getUserSettings(), System.LoggingLevel.INFO, true);
1276+
System.Assert.isNull(builder.getLogEntryEvent().RecordId__c);
1277+
System.Assert.isNull(builder.getLogEntryEvent().RecordJson__c);
1278+
System.Assert.isNull(builder.getLogEntryEvent().RecordSObjectClassification__c);
1279+
System.Assert.isNull(builder.getLogEntryEvent().RecordSObjectType__c);
1280+
System.Assert.isNull(builder.getLogEntryEvent().RecordSObjectTypeNamespace__c);
1281+
1282+
List<Id> userIdList = new List<Id>(new Map<Id, Schema.User>([SELECT Id, Name, Username, IsActive FROM User LIMIT 5]).keySet());
1283+
builder.setRecord(userIdList);
1284+
1285+
System.Assert.areEqual(userIdList.size(), builder.getLogEntryEvent().RecordCollectionSize__c);
1286+
System.Assert.areEqual('List', builder.getLogEntryEvent().RecordCollectionType__c);
1287+
System.Assert.isNull(builder.getLogEntryEvent().RecordId__c);
1288+
System.Assert.isNotNull(builder.getLogEntryEvent().RecordJson__c);
1289+
System.Assert.areEqual('Unknown', builder.getLogEntryEvent().RecordSObjectClassification__c);
1290+
System.Assert.areEqual('Unknown', builder.getLogEntryEvent().RecordSObjectType__c);
1291+
}
1292+
1293+
@IsTest
1294+
static void it_should_set_record_fields_for_set_of_id_records_when_populated() {
1295+
LogEntryEventBuilder builder = new LogEntryEventBuilder(getUserSettings(), System.LoggingLevel.INFO, true);
1296+
System.Assert.isNull(builder.getLogEntryEvent().RecordId__c);
1297+
System.Assert.isNull(builder.getLogEntryEvent().RecordJson__c);
1298+
System.Assert.isNull(builder.getLogEntryEvent().RecordSObjectClassification__c);
1299+
System.Assert.isNull(builder.getLogEntryEvent().RecordSObjectType__c);
1300+
System.Assert.isNull(builder.getLogEntryEvent().RecordSObjectTypeNamespace__c);
1301+
1302+
Set<Id> userIdSet = new Map<Id, Schema.User>([SELECT Id, Name, Username, IsActive FROM User LIMIT 5]).keySet();
1303+
builder.setRecord(userIdSet);
1304+
1305+
System.Assert.areEqual(userIdSet.size(), builder.getLogEntryEvent().RecordCollectionSize__c);
1306+
System.Assert.areEqual('List', builder.getLogEntryEvent().RecordCollectionType__c);
1307+
System.Assert.isNull(builder.getLogEntryEvent().RecordId__c);
1308+
System.Assert.isNotNull(builder.getLogEntryEvent().RecordJson__c);
1309+
System.Assert.areEqual('Unknown', builder.getLogEntryEvent().RecordSObjectClassification__c);
1310+
System.Assert.areEqual('Unknown', builder.getLogEntryEvent().RecordSObjectType__c);
1311+
}
1312+
12521313
@IsTest
12531314
static void it_should_skip_setting_http_request_fields_when_request_is_null() {
12541315
LogEntryEventBuilder builder = new LogEntryEventBuilder(getUserSettings(), System.LoggingLevel.INFO, true);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//------------------------------------------------------------------------------------------------//
2+
// This file is part of the Nebula Logger project, released under the MIT License. //
3+
// See LICENSE file or go to https://github.com/jongpie/NebulaLogger for full license details. //
4+
//------------------------------------------------------------------------------------------------//
5+
6+
// This class intentionally does nothing - it's here to ensure that any references
7+
// in Nebula Logger's codebase use `System.Iterable` instead of just `Iterable`
8+
@SuppressWarnings('PMD.ApexDoc, PMD.EmptyStatementBlock')
9+
public without sharing class Iterable {
10+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>61.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nebula-logger",
3-
"version": "4.14.17",
3+
"version": "4.14.18",
44
"description": "The most robust logger for Salesforce. Works with Apex, Lightning Components, Flow, Process Builder & Integrations. Designed for Salesforce admins, developers & architects.",
55
"author": "Jonathan Gillespie",
66
"license": "MIT",

sfdx-project.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"path": "./nebula-logger/core",
1010
"definitionFile": "./config/scratch-orgs/base-scratch-def.json",
1111
"scopeProfiles": true,
12-
"versionNumber": "4.14.17.NEXT",
13-
"versionName": "Improved JavaScript Console Output",
14-
"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.",
12+
"versionNumber": "4.14.18.NEXT",
13+
"versionName": "Added setRecord() Overload for List<Id> and Set<Id> Parameters",
14+
"versionDescription": "Added a new overload setRecord(System.Iterable<Id> recordsIds) in LogEntryEventBuilder to make it easy to log List<Id> and Set<Id>.",
1515
"releaseNotesUrl": "https://github.com/jongpie/NebulaLogger/releases",
1616
"unpackagedMetadata": {
1717
"path": "./nebula-logger/extra-tests"
@@ -202,6 +202,7 @@
202202
"Nebula Logger - Core@4.14.15-create-log-entry-for-asyncapexcontext": "04t5Y0000015obxQAA",
203203
"Nebula Logger - Core@4.14.16-callablelogger-enhancements": "04t5Y0000015ocHQAQ",
204204
"Nebula Logger - Core@4.14.17-improved-javascript-console-output": "04t5Y0000015ocRQAQ",
205+
"Nebula Logger - Core@4.14.18-added-setrecord()-overload-for-list<id>-and-set<id>-parameters": "04t5Y0000015ocbQAA",
205206
"Nebula Logger - Core Plugin - Async Failure Additions": "0Ho5Y000000blO4SAI",
206207
"Nebula Logger - Core Plugin - Async Failure Additions@1.0.0": "04t5Y0000015lhiQAA",
207208
"Nebula Logger - Core Plugin - Async Failure Additions@1.0.1": "04t5Y0000015lhsQAA",

0 commit comments

Comments
 (0)