Newer Version Available
Publish Event Messages Using Apex
To publish event messages, call the EventBus.publish method. For example, if you’ve defined a custom platform event called Low Ink, reference this event type as Low_Ink__e. Next create instances of this event and pass them to the Apex method.
This example creates two events of type Low_Ink__e, publishes them, and then checks whether the publishing was successful or errors were encountered. The example assumes that the Low Ink platform event is defined in your org.
When you publish events from Apex, they’re inserted synchronously. Because event publishing is equivalent to a DML insert operation, DML limits apply.