Streaming API Flashcards
What is PushTopic, Event and Notification?
PushTopic is a record that defines a channel. Determines what event will cause a notification. Describes the data the notification will contain.
An Event is a modification of a field when creating/updating a record. An even may trigger a notification.
A Notification is the data sent as a result of an event. Notification is sent to clients that are subscribed to the associated Channel.
How would you create a PushTopic?
Construct a new PushTopic object
Specify a Name
Specify a SOQL query
Specify what events should notify the client
pushTopic.NotifyForOperationCreate = true;
(CRUD and Undelete)
Optionally specify values for the PushTopic fields (pushTopic.NotifyForFields = ‘All’;)
Insert PushTopic in database
What is Channel Name?
Subscribes identify a channel using the PushTopic name.
The channel name must match the PushTopic name exactly. /topic/PositionOpen
If the PushTopic name is changed, Live subscriptions are not affected. New subscriptions must use the new channel name.
How to define Events that generate Notifications?
Using NotifyForOperationC/R/U/D/UD
Events may generate a Notification but is not guaranteed
Updates performed by the Bulk API will not generate notifications
When will an Event generate a Notification?
NotifyForFields specifies the fields that should be checked.
- All - avoid using this as this will increase traffic
- Referenced - default
- Select
- Where
Once a record meets the criteria specified in the NotifyForFields, it should then meet the criteria specified in the WHERE clause of the query.
How to define what data is included in the notification?
Only fields included in the SELECT clause of the SOQL on the PushTopic will be sent.
Only records that a User has access to will be sent
The results are returned in a JSON format with the data and event information.
How does security work with PushTopics?
Logged in User must have Read access to the PushTopic object.
Field Level security access for the fields specified in the WHERE clause
Access to the new or modified record based on sharing rules
What are the unsupported queries in a PushTopic?
Queries without an ID in the select clause
Queries with relationships
How would you deactivate a PushTopic?
pushTopic.isActive = false;
update pushTopic;
What are the CometD methods supported by Salesforce?
handshake
subscribe
unsubscribe
disconnect
Is Message Delivery Guaranteed?
Does not guarantee durability and reliable delivery of notifications. Streaming servers don’t maintain any client state and don’t keep track of what is delivered. Some events may not be processed if the system is being heavily used.
If an application server is stopped all the messages being processed but not yet sent are lost. The client must reconnect and subscribe to the channel to receive notifications.
Clients only receive notifications when a channel and subscription are active
For bulkified events that make multiple changes to records only the last change will be included in the notification
What limits apply to the Streaming API?
Maximum number of
- PushTopics
- Clients per PushTopic
- Concurrent clients across all PushTopics
- Events per day
- Length of SOQL query
- Length for a PushTopic Name
How often does a client need to Reconnect?
Reconnect timeout is 40 seconds
How long is the subscription valid?
A client subscription is valid for a specified time irrespective of activity
The client must handshake, subscribe and connect before the session is timed out.
A new subscription creates a new session.
CometD session timeout is 2 hrs
How long is the Socket Timeout?
Client waits on a connection to receive events.
If no events are generated within the socket timeout, the server closes the connection.
The client should reconnect before 2 min to avoid the connection timeout.
Socket Timeout is 110 seconds