Skip to content

Allowing to log SObject without ID field#912

Merged
jongpie merged 7 commits intojongpie:mainfrom
TrangOul:patch-1
Feb 23, 2026
Merged

Allowing to log SObject without ID field#912
jongpie merged 7 commits intojongpie:mainfrom
TrangOul:patch-1

Conversation

@TrangOul
Copy link
Copy Markdown
Contributor

@TrangOul TrangOul commented Oct 3, 2025

Fixes #911 . Skips saving the ID of the record if it doesn’t have one.

The try approach seems to run about ≈ 40×-50× faster than querying the Schema:

if (record.getSObjectType().getDescribe().fields.getMap().containsKey('Id')) {
	this.logEntryEvent.RecordId__c = record.Id
}

and ≈ 6×-7× faster than cached version of the Schema:

private static final Map<String, Boolean> CACHED_SOBJECT_NAME_TO_HAS_ID_FIELD = new Map<String, Boolean>();
private static Boolean getHasIdField(Schema.SObjectType sobjectType) {
	final String sobjectName = sobjectType.toString();
	if (CACHED_SOBJECT_NAME_TO_HAS_ID_FIELD.containsKey(sobjectName)) {
		return CACHED_SOBJECT_NAME_TO_HAS_ID_FIELD.get(sobjectName);
	}
	final Boolean hasIdField = sobjectType.getDescribe().fields.getMap().containsKey('Id');
	CACHED_SOBJECT_NAME_TO_HAS_ID_FIELD.put(sobjectName, hasIdField);
	return hasIdField;
}

(...)

if (this.getHasIdField(record.getSObjectType())) {
	this.logEntryEvent.RecordId__c = record.Id
}

@TrangOul TrangOul requested a review from jongpie as a code owner October 3, 2025 14:40
…gging published platform events no longer throws an exception (due to missing Id field)
@jongpie jongpie added Type: Bug Something isn't working Logging Source: Apex Items related to using Logger within Apex Logging Source: Flow Items related to using Nebula Logger within Flow Logging Source: Lightning Components Items related to using Nebula Logger using JavaScript within lightning components (lwc & aura) Layer: Logger Engine Items related to the core logging engine Logging Source: API Items related to using Nebula Logger via REST API Salesforce Feature: Platform Events Items related to how platform events are leveraged by Nebula Logger Salesforce issue Logging Source: OmniStudio Items related to using Nebula Logger within OmniStudio labels Feb 23, 2026
@jongpie
Copy link
Copy Markdown
Owner

jongpie commented Feb 23, 2026

@TrangOul this looks great, and I appreciate you trying a few different ways to see which one has the best performance! I'm working on merging this PR today - thanks for working on this 🥳

@jongpie jongpie force-pushed the patch-1 branch 3 times, most recently from d01196d to 6f5620f Compare February 23, 2026 16:38
@jongpie jongpie merged commit 57ffd2c into jongpie:main Feb 23, 2026
1 check passed
@jongpie
Copy link
Copy Markdown
Owner

jongpie commented Feb 23, 2026

@TrangOul this is now available in release v4.17.1 - thanks again!

@TrangOul TrangOul deleted the patch-1 branch March 27, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Layer: Logger Engine Items related to the core logging engine Logging Source: Apex Items related to using Logger within Apex Logging Source: API Items related to using Nebula Logger via REST API Logging Source: Flow Items related to using Nebula Logger within Flow Logging Source: Lightning Components Items related to using Nebula Logger using JavaScript within lightning components (lwc & aura) Logging Source: OmniStudio Items related to using Nebula Logger within OmniStudio Salesforce Feature: Platform Events Items related to how platform events are leveraged by Nebula Logger Salesforce issue Type: Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support logging Platform Event SObjects

2 participants