Skip to content

Commit 52be92e

Browse files
authored
Allowing to log SObject without ID field
Fixes #911 The `try` approach seems to run about two orders of magnitude faster than querying the Schema (`record.getSObjectType().getDescribe().fields.getMap().containsKey('Id')`) and one order of magnitude faster than cached version of the Schema (`private static final Map<String, Boolean> CACHED_SOBJECT_NAME_TO_HAS_ID_FIELD ...`)
1 parent 1adf4de commit 52be92e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,11 @@ global with sharing class LogEntryEventBuilder {
460460
this.logEntryEvent.RecordSObjectClassification__c = 'Unknown';
461461
this.logEntryEvent.RecordSObjectType__c = 'Unknown';
462462
} else {
463-
this.logEntryEvent.RecordId__c = record.Id;
463+
try {
464+
this.logEntryEvent.RecordId__c = record.Id;
465+
} catch (System.SObjectException ex) {
466+
// Certain SObjects (such as Platform Events) do not have the ID field
467+
}
464468
this.logEntryEvent.RecordSObjectClassification__c = getSObjectClassification(record.getSObjectType());
465469
this.logEntryEvent.RecordSObjectType__c = record.getSObjectType().toString();
466470
this.logEntryEvent.RecordSObjectTypeNamespace__c = getSObjectTypeNamespace(record.getSObjectType());

0 commit comments

Comments
 (0)