Newer Version Available

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

Match a Publish Result with the Event Published (Beta)

Use the EventUuid field value to match the event status with the event published. The EventUuid field is a universally unique identifier (UUID) that identifies the event message and correlates the publish result of each event with the original publish call.

As a beta feature, Publish Status Events is a preview and isn’t part of the “Services” under your master subscription agreement with Salesforce. Use this feature at your sole discretion, and make your purchase decisions only on the basis of generally available products and features. Salesforce doesn’t guarantee general availability of this feature within any particular time frame or at all, and we can discontinue it at any time. This feature is for evaluation purposes only, not for production use. It’s offered as is and isn’t supported, and Salesforce has no liability for any harm or damage arising out of or in connection with it. All restrictions, Salesforce reservation of rights, obligations concerning the Services, and terms for related Non-Salesforce Applications and Content apply equally to your use of this feature. You can provide feedback and suggestions for Publish Status Events in the Trailblazer Community. For information on enabling this feature in your org, contact Salesforce.

Note

After getting the EventUuid field value, save the UUID along with event field values. If you save event field values, you can republish the same events if the publishing fails.

If you published the event using Salesforce APIs, the SaveResult returned contains the UUID in the Error message field. This example contains the save result of an event inserted using a REST API POST request.

1{
2  "id" : "e01xx0000000001AAA",
3  "success" : true,
4  "errors" : [ {
5    "statusCode" : "OPERATION_ENQUEUED",
6    "message" : "e981b488-81f3-4fcc-bd6f-f7033c9d7ac3",
7    "fields" : [ ]
8  } ]
9}

If you published the event in Apex, you can obtain the UUID by calling EventBus.getOperationId(saveResult).

This example gets the UUID from the event publish call using Apex.

Prerequisites: Before you can run this example, define a platform event with the label of Order Event and the following fields: Order Number of type Text(10) and Has Shipped of type Checkbox.

1// Publish a high-volume event message
2Order_Event__e evt = new Order_Event__e(
3    Order_Number__c='17',
4    Has_Shipped__c = false);
5Database.SaveResult sr = EventBus.publish(evt);
6// Inspect immediate result
7if (sr.isSuccess() == true) {
8    System.debug('Successfully enqueued event for publishing.');
9    // Get the UUID that uniquely identifies this event publish
10    System.debug('UUID=' + EventBus.getOperationId(sr));
11} else {
12   for(Database.Error err : sr.getErrors()) {
13       System.debug('Error returned: ' +
14                    err.getStatusCode() +
15                    ' - ' +
16                    err.getMessage());
17   }
18}
19
20// Debug message output:
21//|DEBUG|Successfully enqueued event for publishing.
22//|DEBUG|UUID=6ba5db7e-c27b-4a67-a3c5-cf425ffcaf53