Newer Version Available

This content describes an older version of this product. View Latest

EventBus Class

Contains methods for publishing platform events.

Namespace

System

Usage

To learn how to use platform events in Apex, see Publish Platform Events.

EventBus Methods

The following are methods for EventBus. All methods are static.

publish(event)

Publishes the given platform event. To receive published events, use triggers for the corresponding event object.

Signature

public static Database.SaveResult publish(SObject event)

Parameters

event
Type: SObject
An instance of a platform event. You must define your platform event object first in your org. For example, the type of the platform event object can be MyEvent__e.

Return Value

Type: Database.SaveResult

The result of publishing the given event.

Usage

This method inserts events synchronously. The insertion is part of an Apex transaction. Apex DML limits, such as number of records processed in DML statements, apply to this method.

Note

publish(events)

Publishes the given list of platform events. To receive published events, use triggers for the corresponding event object.

Signature

public static List<Database.SaveResult> publish(List<SObject> events)

Parameters

events
Type: List<sObject>
A list of platform event instances. You must define your platform event object first in your org. For example, the type of the platform event object can be MyEvent__e.

Return Value

Type: List<Database.SaveResult>

A list of results, each corresponding to the result of publishing one event.

Usage

This method inserts events synchronously. The insertion is part of an Apex transaction. Apex DML limits, such as number of records processed in DML statements, apply to this method.

Note