If my Platform Event
is configured to have a custom field Key_Field__c
.
How do I get the value of Key_Field__c
on the Platform Event
object which has failed when using EventBus.publish()
void createEvents() {
List<My_Custom_Event__e > events = new List<My_Custom_Event__e>();
events.add(new My_Custom_Event__e(Key_Field__c = 'key field value 1'));
events.add(new My_Custom_Event__e(Key_Field__c = 'key field value 2'));
handleSaveResults(EventBus.publish(events));
}
void handleSaveResults(Database.SaveResult[] results) {
for (Database.SaveResult result : results) {
if (result.isSuccess() == false) {
for (Database.Error err : result.getErrors()) {
String statusCode = err.getStatusCode();
String message = err.getMessage();
String fields = err.getFields();
// How do I get the value of Key_Field__c ?
}
}
}
}
Because I need to know which record failed, so it can be re-processed manually
Question
To recap: How to I get the value of a custom field on the Platform Event
, via the Database.SaveResult
or Database.Error
objects?