Thursday 13 December 2018

Streaming API - PushTopic

1. What Salesforce Streaming API?
The Salesforce Streaming API is a simple way to push relevant data to your users in real-time, instead of having to refresh the screen to get new information.

This allows a user to get information without having to perform any action to retrieve it, essentially pushing new data to the screen.


2. Event-Driven (Pub/Sub) VS Point-Point Architecture Best Fit?

Event-Driven [Push Technology]
Point-Point [Pull Technology]
At some point enterprise system grows much and more complex and where decoupling of service is needed.There event driven architecture is the best fit.

When your infrastructure only has a few components, point to point integration can seem like a lightweight way to connect everything together.

3. What are the Streaming API events?

Event
Details
PushTopic  
PushTopic events track field changes in
Salesforce records and are tied to Salesforce records.
Generic
Generic events contain arbitrary payloads.



4. Explain Streaming API PushTopic event?

You can use Streaming API to keep your external source in sync with your 
Salesforce data with PushTopic events and Change Data Capture events.

Streaming API lets you process business logic in an external system in 
response to data changes in Salesforce.

Ex: Notify a fulfillment center whenever an opportunity is updated.

PushTopic Supported Objects :
Supports all Custom Objects & Below mentioned Standard Objects

Campaign
ContractLineItem
Case
Lead
Entitlement
ServiceAppointment
Account
Quote
ServiceContract
Contact
QuoteLineItem
WorkOrder
Opportunity
-
WorkOrderLineItem
Task
-
LiveChatTranscript

PushTopic Important Points :

1.The SELECT  statement's field list must include Id
2.Only 1 object per query is allowed
3.Aggregate queries or Semi-Joins aren't supported
4.Subscribers receives all stored events after the events specified by its replayId value and new events.
5.Limit the stream of events to only those events that match a subscription filter,Only PushTopic has this feature ,Same is not available in Generic /Platform Events.
6.Clients & Timeouts  - As a supported in the Bayeux protocol
  •   Socket timeout : 110 Seconds
  •   Reconnect timeout : 40 Seconds


PushTopic Governor Limits: Refer
PushTopic Implementation Example :
1.Apex :

PushTopic pushTopic = new PushTopic();
pushTopic.Name = 'ContAddUpdate';
pushTopic.Query = 'SELECT Id,Name,AccountId,MailingCity,MailingStreet'+
          'FROM Contact Where AccountId = 016F000032XRPhQAO';
pushTopic.ApiVersion = 43.0;
pushTopic.NotifyForOperationCreate = true;
pushTopic.NotifyForOperationUpdate = true;
pushTopic.NotifyForOperationUndelete = true;
pushTopic.NotifyForOperationDelete = true;
pushTopic.NotifyForFields = 'Referenced';
insert pushTopic;

2.WorkBench: Publish & Subscribe - Change Data Capture on records






How to delete PushTopic :

There are 2 options,Either deactivate /delete 

Deactivate :
PushTopic pt = new PushTopic(Id='0IFD0000000008jOAA', IsActive = false); update(pt);
Delete : Apex
List<PushTopic> pts = [SELECT Id FROM PushTopic WHERE Name = 'Channel'];
Database.delete(pts);

Delete : Workbench
Select queries -> Streaming Push Topics -> select your push topic --> Details --> Delete




No comments:

Post a Comment