Platform event is appended with__e suffix for API name of the event.
You can not query Platform events through SOQL or SOSL.
You can not use Platform in reports, list views, and search. Platform events don’t have an associated tab
Published platform events can’t be rolled back.
All platform event fields are read-only by default
Only after insert Triggers Are Supported
You can access platform events both through API and declaratively
You can control platform events though Profiles and permissions
Summary
Platform events simplify the process of communicating changes and responding to events. Platform events can be used to Overcome Salesforce Governor Limits.
Salesforce event-driven architecture is consisting of
event producers
event consumers
channels.
Platform events simplify the process of communicating changes and responding to events. Publishers and subscribers communicate with each other through events. One or more subscribers can listen to the same event and carry out actions.
With an Event-driven architecture each service publishes an event whenever it updates or creates a data. Other services can subscribe to events. It enables an application to maintain data consistency across multiple services without using distributed transactions.
Let us take an example of order management. When the Order management app creates an Order in a pending state and publishes an Order Created event. The Customer Service receives the event and attempts to process an Order. It then publishes an Order Update event. Then Order Update Service receives the event from the changes the state of the order to either approved or canceled or fulfilled. The following diagram show the event driven architect
Terminology
Advertisements
REPORT THIS AD
Event
A change in state that is meaningful in a business process. For example, a placement of an order is a meaningful event because the order fulfillment center requires notification to process the order.
Event Notifier
A message that contains data about the event. Also known as an event notification.
Event producer
The publisher of an event message over a channel.
Channel
A conduit in which an event producer transmits a message. Event consumers subscribe to the channel to receive messages.
Event consumer
A subscriber to a channel that receives messages from the channel. A change in state that is meaningful in a business process.
But when you overlook at Platform events it makes similar to Streaming API and most of the futures including the replayID and durability but below makes the difference between with streaming API.
Platform events are special kinds of entity similar to custom object
You can publish and consume platform events by using Apex or a REST API or SOAP API.
Platform events integrate with the Salesforce platform through Apex triggers. Triggers are the event consumers on the Salesforce platform that listen to event messages.
Unlike custom objects, you can’t update or delete event records. You also can’t view event records in the Salesforce user interface, and platform events don’t have page layouts. When you delete a platform event definition, it’s permanently deleted.
Platform events may be published using declarative tools (Process Builder)
platform events can also be subscribed to using APEX or decoratively process builder and flows
Publishing and subscribing Platform events
Publishing and subscribing the platform event are more flexible. You can publish event messages from a Force.com app or an external app using Apex or Salesforce APIs and you can subscribe from the Salesforce or external apps or use long polling with cometD as well.
Define Plat form Event
Define platform event similar like custom object, go to setup –> develope –> Platform events –> create new platform events as shown below.
Publish Platform events
1.a. Publish Using Apex
A trigger processes platform event notification sequentially in the order they’re received and trigger runs in its own process asynchronously and isn’t part of the transaction that published the event. Salesforce has a special class to publish the platform events EventBus which is having methods publish method. once the event is published you can consume the events from the channel
trigger PlatformEventPublish on Account (after insert , after update ) {
If(trigger.isAfter && trigger.isUpdate){
List<Employee_On_boarding__e> publishEvents = new List<Employee_On_boarding__e>();
for(Account a : Trigger.new){
Employee_On_boarding__e eve = new Employee_On_boarding__e();
eve.Name__c = a.Name ;
eve.Phone__c = a.Phone ;
eve.Salary__c = a.AnnualRevenue ;
publishEvents.add(eve);
}
if(publishEvents.size()>0){
EventBus.publish(publishEvents);
}
}
}
1.b. Publish Using Process Builder
1.c. Publish Events by Flow
Create flow: 1(platform Event producer)
Create flow:2(Platform Event Consumer)
Run/Debug Flow:1(platform Event producer) and you will send post in chatter.
Result:
1.d. Publish Events by Using API (Using workbench)
Subscribe for Platform events
We can subscribe to the platform events from the Platform events object trigger which is created in step 1. Here is the sample trigger show how you can handle the subscribed events. create new accounts from the platform event but you can implement your own business logic to update the data.
Below is simple visual force page that consumes the platform events which you published. This page is built on cometD.
CometD is a set of library to write web applications that perform messaging over the web.Whenever you need to write applications where clients need to react to server-side events, then CometD is a very good choice. Think chat applications, online games, monitoring consoles, collaboration tools, stock trading, etc.
you can consume the platform events by using this URI /event/Employee_On_boarding__e and the Complete code is here below.
Today we are going to discuss How to Get Custom Label Using SOQL
Custom labels are custom text values that can be accessed from Apex classes, Visualforce pages, or Lightning components. The values can be translated into any language Salesforce supports.
the Custom Labels in org write the following SOQL Query. Note: Use Tooling API to Query