-
-
Notifications
You must be signed in to change notification settings - Fork 207
Open
Labels
Type: EnhancementNew feature or requestNew feature or request
Description
Support logging Platform Event SObjects in setRecord(SObject)
Platform Events are SObjects:
Object obj = new MyPlatformEvent__e(MyField__c = 'MyValue');
System.debug(obj instanceof SObject);true
However, trying to log them with the usual setRecord(SObject) (or deprecated setRecordId(SObject)) fails:
MyPlatformEvent__e evt = new MyPlatformEvent__e(MyField__c = 'MyValue');
EventBus.publish(evt);
Logger.fine('Platform Event Log').setRecord(evt);
Logger.saveLog();Error on line 463, column 1: System.SObjectException: Invalid field Id
Class.LogEntryEventBuilder.setRecord: line 463, column 1
AnonymousBlock: line 3, column 1
AnonymousBlock: line 3, column 1
OTOH, logging a list of platform events with setRecord(List<SObject>) works:
List<MyPlatformEvent__e> evts = new List<MyPlatformEvent__e>{
new MyPlatformEvent__e(MyField__c = 'MyValue'),
new MyPlatformEvent__e(MyField__c = 'MyValue2')
};
EventBus.publish(evts);
Logger.fine('Platform Events Log').setRecord(evts);
Logger.saveLog();
The issue with a single record is that the Logger tries to read the record's ID, and Platform Events do not have one.
After commenting the line 463 in LogEntryEventBuilder, the log is saved correctly (although, obviously, without the record ID or link to it):
class LogEntryEventBuilder {
(...)
//this.logEntryEvent.RecordId__c = record.Id;
EventUuid field could be used in place of the Id, but its format is incompatible with Salesforce IDs (and RecordId__c).
Metadata
Metadata
Assignees
Labels
Type: EnhancementNew feature or requestNew feature or request