1) How can you publish a platform event using Apex?
You can publish a platform event using the EventBus.publish()
method in Apex. Here's how:
- Create an instance of the platform event object and populate its fields.
- Use
EventBus.publish()
to publish the event, which returns aDatabase.SaveResult
. - Check
isSuccess()
on the result to determine whether the event was published successfully.
EventUuid
ensures the identification of an event message across different scenarios, including maintenance activities.Although platform event triggers run asynchronously, the synchronous limits apply to platform event triggers. This is because Asynchronous limits are for long-lived processes, such as Batch Apex and future methods. Synchronous limits are for short-lived processes that execute quickly and platform event triggers are short-lived processes that execute in batches rather quickly.
Because a platform event trigger runs in a separate transaction from the one that fired it, governor limits are reset, and the trigger gets its own set of limits.
PlatformEventSubscriberConfig
via Tooling API or Metadata API.- Default Configuration: Runs as the Automated Process user with a batch size of 2,000.
- Custom Configuration: Specify a custom user and a batch size between 1 and 2,000. Smaller batch sizes help avoid hitting governor limits.
PlatformEventSubscriberConfig?
To get or manipulate a configuration, use this endpoint with the ID of your PlatformEventSubscriberConfig record appended.
/services/data/v60.0/tooling/sobjects/PlatformEventSubscriberConfig/<ID>
You can also,
· Delete a specific configuration with a DELETE request.
· Update a specific configuration with a PATCH request. For this request, include the PlatformEventSubscriberConfig definition in the request body.
To subscribe to platform events, use the channel name /event/Event_Name__e
in a CometD client. For example, to subscribe to a TestEvent__e
platform event, use the channel /event/TestEvent__e
. The CometD client receives real-time event notifications in JSON format.
7) How can you encrypt platform event messages in the event bus?
To encrypt platform event messages:
- Create an event bus tenant secret in the Key Management page in Setup.
- Enable encryption for platform events on the Encryption Policy page.
Without Shield Encryption, messages are stored in clear text in the event bus.
PlatformEventUsageMetric
object to monitor event publishing and delivery usage. Example queries:To retrieve the usage of platform events:
Events Delivered (April 26, 2024, 11:00 to April 27, 2024, 11:00):
SELECT Name, StartDate, EndDate, Value
FROM PlatformEventUsageMetric
WHERE Name='PLATFORM_EVENTS_DELIVERED'
AND StartDate=2024-04-26T11:00:00.000Z
AND EndDate=2024-04-27T11:00:00.000Z
Subscription Methods: CometD, Pub/Sub API, empApi Lightning components, and event relays.
Note: Delivery metrics exclude event deliveries to Apex triggers, flows, and processes.
No comments:
Post a Comment