Slaesforce FAQ

how to publish platform event in salesforce

by Alexandra Morar Published 2 years ago Updated 2 years ago
image

If your app is on the Salesforce platform, you can publish events using an Apex method or with declarative tools, such as Process Builder or Flow Builder. If your app is an external app, you can publish events using Salesforce APIs. To publish event messages, you create an instance of the event and pass it to the EventBus.publish () method.

Full Answer

How do I publish an event in Salesforce apex?

Use Apex to publish event messages from a Salesforce app. To publish event messages, call the EventBus.publish method. For example, if you defined a custom platform event called Low Ink, reference this event type as Low_Ink__e. Next, create instances of this event, and then pass them to the Apex method.

What are platform events in Salesforce?

Use platform events to connect business processes in Salesforce and external apps through the exchange of real-time event data. Platform events are secure and scalable messages that contain data. Publishers publish event messages that subscribers receive in real time.

Is it possible to publish a platform event without side effects?

@AdrianLarson yes, the question is about covering method which only publishes a platform event without side effects – Patlatus Jan 17 '18 at 10:16 1

Is eventlist asynchronous in Salesforce apex?

@GlenMazza No, it is not, the eventList property lives during transaction, and transaction lives up to 10 seconds in synchronous mode or 60 seconds in asynchronous mode – Patlatus Jul 1 '21 at 7:21 @Patlatus Thanks for the response. I'm a Java developer, and just starting to learn Apex.

image

How do I send a platform event in Salesforce?

Define and Publish Platform EventsDefine a platform event.Describe how platform event messages can be published.Use an Apex method to publish an event.Publish an event using clicks in a process or flow.Publish an event using REST API by inserting an sObject.

How do I publish a platform event from trigger?

Publishing Salesforce platform events via Apex triggers and REST controllersDefine the custom platform event. The Trailhead tutorial shows how platform events are defined. ... Create an Apex trigger (and test class) to activate generator based on desired criteria.. ... Subscribe to the event messages.

When platform events are published?

Platform events are scalable and secure messages holding data. The publishers publish the event messages that the subscribers receive in real-time. If one wants to modify the data publishes, he needs to define platform event fields.

How do I add a platform event record in Salesforce?

Setting up the Platform Event We need to create a custom platform event within Salesforce and add fields to that event. You will recognize this process as it mimics many of the steps in creating a custom object, custom metadata, or custom setting. In Quick Find in the Setup menu, enter “Platform Events.”

How do you publish a platform event in Test class?

To publish platform events in an Apex test, enclose the publish statements within Test. startTest() and Test. stopTest() statements. Call the publish method within the Test.

How do I create a platform event in Salesforce flow?

Go to Setup à Enter and choose Flows. Click on New Flow and choose Platform Event-Triggered Flow. Choose respective Platform event object to subscribe in the Start element. Drag and drop Create record element and capture the published Platform event field values with the respective Salesforce object.

How do I see platform events in Salesforce?

View Event Subscribers From Setup, enter Platform Events in the Quick Find box, then select Platform Events. Click your event's name. On the event's definition page, the Subscriptions related list shows all the active triggers, processes, and platform event–triggered flows that are subscribed to the platform event.

How do I test a platform event in Salesforce?

Add Apex tests to test platform event subscribers. Before you can package or deploy Apex code, including triggers, to production, it must have tests and sufficient code coverage....Testing Your Platform Event in ApexEvent and Event Bus Properties in Test Context. ... Deliver Test Event Messages. ... Test Retried Event Messages.

What is platform event flow in Salesforce?

Platform Events in Salesforce Platform Event is based on Event-Driven Architecture which enable apps to communicate inside and outside of Salesforce. Platform events are based on the publish/subscribe model and work directly with a message bus which handles the queue of incoming events and processes listening for them.

How do I enable platform events in Salesforce?

We can publish the platform events in 3 ways:Publish Events Messaging using APEX.Publish Events Messaging using Declarative tools (Process Builder or Cloud Flow Designer Tool / Visual Work flow).Publish Events Messaging using Salesforce API from external app.

Can we deploy platform events in Salesforce?

If your app is on the Salesforce platform, you can publish events using an Apex method or with declarative tools, such as Process Builder or Flow Builder. If your app is an external app, you can publish events using Salesforce APIs.

How do I give access to a platform event?

To subscribe to or publish messages to Salesforce custom platform events, you must configure permissions in your Salesforce environment.Log in to Salesforce.Under. Administer. on the left pane, click. Manage Users. ... Edit the profile to assign object permissions to the Salesforce custom platform event that you created.

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 data. This example creates one event of type Low_Ink__e in REST API.

REST API Composite Resource

To publish multiple platform event messages in one REST API request, use the composite resource. Send a POST request to the following endpoint.

Example

This composite request contains two platform events in the request body.

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 event messages in one call. Each event has one custom field named Printer_Model__c.

Follow Along with Trail Together

Want to follow along with an instructor as you work through this step? Take a look at this video, part of the Trail Together series on Trailhead Live.

Test the Chatter Trigger

Now you can test your work. Create a Chatter post to ensure that it triggers a notification.

image
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9