Newer Version Available
Publish Event Messages with Salesforce APIs
Publish events by creating records of your event in the same way that you insert sObjects. You can use any Salesforce API to create platform events, such as SOAP API, REST API, or Bulk API.
When publishing an event message, the result that the API returns contains information about whether the operation was successful and the errors encountered. If the success field is true, the event was published for a standard-volume event. For a high-volume event, the publish request is queued in Salesforce and the event message might not be published immediately. If the success field is false, the event publish operation resulted in errors, which are returned in the errors field.
The returned result also contains the Id system field. The Id field value is not included in the event message delivered to subscribers. It is not used to identify an event message, and is not always unique. Subscribers can use the ReplayId system field, which is included in the delivered message, to identify the position of the event in the stream.
REST API
To publish a platform event message using REST API, send a POST request to the following endpoint.
Example
If you’ve defined a platform event named Low Ink, publish event notifications by inserting Low_Ink__e records. This example creates one event of type Low_Ink__e in REST API.
REST endpoint:
Request body:
After the platform event record is created, the REST response looks like this output. Headers are deleted for brevity.
SOAP API
To publish a platform event message using SOAP API, use the create() call.
Example
This example shows the SOAP message (using Partner API) of a request to create three platform events in one call. Each event has one custom field named Printer_Model__c.
The response of the Partner SOAP API request looks something like the following. Headers are deleted for brevity.