An application programming interface (API) is an interface that easily connects different applications and allows them to work simultaneously.
Salesforce offers a plethora of APIs to its users to make efficient use of its platform by creating related applications. Salesforce’s APIs are SOAP API, REST API, BULK API, METADATA API, TOOLING API, STREAMING API, etc.
Each API provided by Salesforce has a different use case. Cloud Analogy is among the top Salesforce consultants to provide guidance relevant to Salesforce use cases.
Today, we will look into only one of its most interesting APIs, the Streaming API.
What is Streaming API?
Streaming API enables developers to catch real-time events inside a custom web component.
It does so by using push technology and facilitates the developers with a subscription mechanism to receive events like PushTopic events, generic events, platform events, and Change Data Capture events.
Streaming API helps to keep your external sources in sync with Salesforce data with Change Data Capture and PushTopic events.
We will focus on catching a Change Data Capture event inside a custom LWC component.
How does the Streaming API Work?
Streaming API works on a stream subscription mechanism to make it easier, a platform event or a change data capture event with a data stream.
It enables developers to subscribe to this stream whenever there’s a hindrance in the stream, which can occur due to some change in data like an insert, update or delete in case of change data capture events.
It can be a hindrance caused by pushing an event through custom Apex code in case of platform events. It captures that and pushes that event into our component, enabling developers to make necessary changes and display up-to-date data on their component.
In this blog, you will learn how this would work by creating a live chat box using LWC, Streaming API, and a change data capture event.
LWC Live Chat
Before we get our hands dirty with code, there are some prerequisites you will need to complete.
- Let’s start with creating a custom object. We have called it UserConversation in this tutorial, but you can use any name you want to be given and change the API name where required.
- After creating the custom object add the following fields to it.
- Then add your custom object to change the data capture events list.
- Open up your VScode and create an LWC component and its Apex controller. Now it’s time to get our hands dirty with some good code.
Do you intend to catch real-time events inside a custom web component by using push technology and facilitating with a subscription mechanism without any outdated data that might not have been reloaded?
Cloud Analogy, a leading Certified Salesforce Consulting company, is here to provide you with valuable business advice. We offer cost-efficient Salesforce Consulting services to grow your business in various ways, acting as your trusted Salesforce consulting partner.
Connect with our proficient and certified team at Cloud Analogy to start your project today.