Create an Event with an EventUuid Field

The EventUuid field uniquely identifies an event message and is used to match the events returned in the callback result with the events in the publish call. To have the system generate an EventUuid field value in each event object, use the SObjectType.newSObject(recordTypeId, loadDefaults) Apex method to create the event object.
1Order_Event__e event = (Order_Event__e)Order_Event__e.sObjectType.newSObject(null, true);
2
3// The EventUuid value is returned after object creation
4System.debug('EventUuid: ' + event.EventUuid);
5
6// Debug output
7// EventUuid: 19bd382e-8964-43de-ac01-d5d82dd0bf78

If you aren’t interested in correlating the events in the publish call with the publish results, you don’t need the EventUuid value in the created event. In this case, you can create the event by using the event API name directly, which doesn’t include the EventUuid value in the event object. For example: Order_Event__e event = new Order_Event__e();.

Note