Platform Event is an Event-Driven architecture and used to connect and exchange real-time event data in Salesforce and external apps. Transferring data between the publisher and subscriber is secure and scalable. One or more Subscribers can listen to the published event messages.
Use Case
Collect and store the employee information in Salesforce and send an email to the respective employee in Salesforce Community (as a Site guest user profile without logging to the Community) using Flows and Platform Events.
How to create Platform Events?
- Go to Setup à Enter and choose Platform Events.
- Click New Platform Event and set a name for your Platform event and click Save.
- Create Custom fields as per your requirement under the Custom Fields & Relationships section. Custom fields support only the following data types,
- Checkbox
- Date
- Date/Time
- Number
- Text
- Text Area (Long)

Publishing the Platform Event
There are many ways to publish platform events such as Apex, Process builder, Flows and by using Salesforce API’s. Here, we are using Flow builder to publish the platform events. By using Flows, we can interact and collect the information from the end-user and this option is available only in the flows. Below find the steps to publish the platform events using the Flows:
- Go to Setup à Enter and choose Flows.
- Click New Flow and choose Screen flow.
- As shown in the below screenshot, create a Screen with the necessary input fields to get the information from the end user.
- Add a Create record element then choose the created Platform event object and map the custom fields with the end user input. Once the Platform Event record gets created, the event messages are transferred through the Event Channel.
- Finally, Save and Activate the flow.

Subscribe to Platform Events
Published event messages can be received by using Apex trigger, Process builder, Flows or CometD (external clients) subscription method. To subscribe to the platform events through the Flow builder,
- 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.
- Drag and drop Action element and choose Email from the Category to send an Email notification to the respective end user.
- Finally, Save and Activate the flow.

Collect the input from the user using Screen Flow
               As mentioned in the publisher flow, create a Screen to get the inputs from the user. After creating a Platform event object with the respective fields, map the end user screen input values with the platform event fields in the Create record element to publish an event. While running the flow, it shows the screen to get the real-time data from the user and based on the input, the platform event gets published.

Store the input and send an email using Platform Event-Triggered Flow
Once the platform event is published, then the respective subscriber as mentioned in the subscriber flow gets the published event messages. By using the Platform Event-Triggered Flow, we can get and store the information in Salesforce. Action element in Flows has an option to send an email to the user based on the published input. Optionally, we can use the event messages in the email template subject and body as merge fields.


References                                                                                                                     Â
https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_publish.htm
https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_subscribe.htm