Added new Apex method & JavaScript function Logger.setField()
Many thanks to @surajp for sharing some awesome perspectives & suggestions for improving custom field mappings!
Custom field mappings were introduced a few months ago for Apex in v4.13.14
, and for lightning components in v4.14.16
. Both releases provided the ability to set custom fields on individual log entries - but in situations where a custom field should be set on every generated log entry, setting the field on each entry was very repetitive & tedious & repetitive. It was also repetitive.
- This release adds the ability to now set fields once per transaction (in Apex) or once per component instance (in JavaScript) - all subsequent log entries will then automatically have your custom field values applied.
- Individual log entries can still have additional field values set & mapped, giving you multiple options for setting your custom fields.
Core Unlocked Package Changes
New Apex Method Logger.setField()
Resolved #769 by adding a new static method, Logger.setField()
. This gives Apex developers a way to set field(s) once per transaction, and the fields will be auto-populated on all LogEntryEvent__e
records generated in that transaction.
-
The
setField()
method has 2 overloads (same as the instance method overloadsLogEntryEventBuilder.setField()
that were introduced in releasev4.13.14
)Logger.setField(Schema.SObjectField field, Object fieldValue)
- useful for easily setting the value for a single fieldLogger.setField(Map<Schema.SObjectField, Object> fieldToValue)
- useful for setting the value for multiple fields
-
The new method supplements the functionality introduced in release
v4.13.14
, as shown below:// 🥳New! // Set a custom field on all LogEntryEvent__e records in a transaction, // using static method Logger.setField() Logger.setField(LogEntryEvent__e.Some_Custom_Field__c, 'the value for all generated entries') // ℹ️Existing - introduced in v4.13.14 // Set a custom field on a single LogEntryEvent__e record, // using instance method LogEntryEventBuilder.setField() Logger.info('hello, world').setField(LogEntryEvent__e.Another_Custom_Field__c, 'the value for this specific entry');
New JavaScript Function logger.setField()
Added JavaScript support for setting fields once per component instance, using logger.setField()
. This is the JS equivalent of the new Apex method Logger.setField()
(above).
export default class LoggerLWCImportDemo extends LightningElement {
logger = getLogger();
connectedCallback() {
// 🥳New!
// Set My_Field__c on every log entry event created in this component with the same value
this.logger.setField({My_Field__c, 'some value that applies to any subsequent entry'});
// ℹ️Existing - introduced in v4.14.6
this.logger.warn('hello, world - "a value" set for Some_Other_Field__c').setField({ Some_Other_Field__c: 'a value' });
}
}
Installation Info
Core Unlocked Package - no namespace
Full Changelog: v4.14.13...v4.14.14
- SF CLI:
sf package install --wait 20 --security-type AdminsOnly --package 04t5Y0000015oWIQAY
- SFDX CLI:
sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y0000015oWIQAY
- Sandbox: https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015oWIQAY
- Production: https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015oWIQAY