Subscribe with Apex Triggers
With Apex triggers, you can capture and process change events on the Lightning Platform. Change event triggers run asynchronously after the database transaction is completed. Perform resource-intensive business logic asynchronously in the change event trigger, and implement transaction-based logic in the Apex object trigger. By decoupling the processing of changes, change event triggers can help reduce transaction processing time.
-
Change Event Triggers
Because change events are based on platform events, they share characteristics for subscription with Apex platform event triggers. Also, change event messages in triggers contain header and record fields, and some additional fields not present in JSON event messages.
-
Apex Trigger Quick Start
Create an Apex trigger that captures change event messages.
-
Apex Trigger Example
This sample trigger demonstrates a common use for change event triggers and provides a more complex trigger example than the quick start.
-
Test Change Event Triggers
Before you can package or deploy Apex change event triggers to production, you must provide Apex tests and sufficient code coverage.
-
Change Event Trigger Considerations
Keep these considerations in mind when working with change events in Apex triggers.
-
Obtain Apex Trigger Subscribers
To get information about the triggers that are subscribed to change events, query the EventBusSubscriber standard object using SOQL. EventBusSubscriber contains information about Apex triggers but not CometD or Pub/Sub API subscribers.