Force.com Streaming API Developer Guide

Save this PDF as:

Size: px
Start display at page:

Download "Force.com Streaming API Developer Guide"

Transcription

1 Force.com Streaming API Developer Guide Version 41.0, Winter Last updated: December 8, 2017

2 Copyright salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of salesforce.com, inc., as are other names and marks. Other marks appearing herein may be trademarks of their respective owners.

3 CONTENTS GETTING STARTED WITH FORCE.COM STREAMING API Chapter 1: Introducing Streaming API Push Technology Bayeux Protocol, CometD, and Long Polling Streaming API Terms How the Client Connects Message Reliability Message Durability Chapter 2: Quick Start Using Workbench Prerequisites Step 1: Create an Object Step 2: Create a PushTopic Step 3: Subscribe to the PushTopic Channel Step 4: Test the PushTopic Channel Chapter 3: Code Examples Example: Subscribe to and Replay Events Using a Visualforce Page Prerequisites Deploy a Sample Project to Your Org Assign a Permission Set Durable PushTopic Streaming Sample Durable Generic Streaming Sample Replay Events Sample: Code Walkthrough Example: Interactive Visualforce Page without Replay Prerequisites Step 1: Create an Object Step 2: Create a PushTopic Step 3: Create the Static Resources Step 4: Create a Visualforce Page Step 5: Test the PushTopic Channel Example: Subscribe to and Replay Events Using a Java Client Prerequisites Step 1: Create an Object Step 2: Create a PushTopic Step 3: Download and Build the Project Step 4: Use the Connector with Username and Password Login Step 5: Use the Connector with OAuth Bearer Token Login Learn More About EMP Connector

4 Contents Example: Authentication Set Up Authentication for Developer Testing Set Up Authentication with OAuth USING STREAMING API Chapter 4: Working with PushTopics PushTopic Queries Security and the PushTopic Query Supported PushTopic Queries Compound Fields in PushTopic Queries Unsupported PushTopic Queries Event Notification Rules Events Notifications Replay PushTopic Streaming Events Filtered Subscriptions Bulk Subscriptions Deactivating a Push Topic Chapter 5: Streaming API Considerations Clients and Timeouts Clients and Cookies for Streaming API Supported CometD Versions HTTPS Recommended Debugging Streaming API Applications Monitoring Events Usage Notification Message Order Considerations for Multiple Notifications in the Same Transaction GENERIC STREAMING Chapter 6: Introducing Generic Streaming Replay Generic Streaming Events with Durable Generic Streaming Chapter 7: Generic Streaming Quick Start Create a Streaming Channel Run a Java Client with Username and Password Login Run a Java Client with OAuth Bearer Token Login Generate Events Using REST REFERENCE Chapter 8: PushTopic Chapter 9: StreamingChannel

5 Contents Chapter 10: Streaming Channel Push Chapter 11: Streaming API Limits INDEX

6

7 GETTING STARTED WITH FORCE.COM STREAMING API CHAPTER 1 Introducing Streaming API In this chapter... Push Technology Bayeux Protocol, CometD, and Long Polling Use Streaming API to receive notifications for changes to Salesforce data that match a SOQL query you define, in a secure and scalable way. These events can be received by: Pages in the Salesforce application. Application servers outside of Salesforce. Streaming API Terms Clients outside the Salesforce application. How the Client Connects Message Reliability Message Durability The sequence of events when using Streaming API is as follows: 1. Create a PushTopic based on a SOQL query. This defines the channel. 2. Clients subscribe to the channel. 3. A record is created, updated, deleted, or undeleted (an event occurs). The changes to that record are evaluated. 4. If the record changes match the criteria of the PushTopic query, a notification is generated by the server and received by the subscribed clients. Streaming API is useful when you want notifications to be pushed from the server to the client based on criteria that you define. Consider the following applications for Streaming API: Applications that poll frequently Applications that have constant polling action against the Salesforce infrastructure, consuming unnecessary API calls and processing time, would benefit from Streaming API which reduces the number of requests that return no data. General notification Use Streaming API for applications that require general notification of data changes in an organization. This enables you to reduce the number of API calls and improve performance. Note: You can use Streaming API with any organization as long as you enable the API. This includes both Salesforce and Database.com organizations. 1

8 Introducing Streaming API Push Technology Push Technology Push technology, also called the publish/subscribe model, transfers information that is initiated from a server to the client. This type of communication is the opposite of pull technology in which a request for information is made from a client to the server. The information sent by the server is typically specified in advance. When using Streaming API, you specify the information that the client receives by creating a PushTopic. The client then subscribes to the PushTopic channel and is notified of events that match the PushTopic criteria. In push technology, the server pushes out information to the client after the client has subscribed to a channel of information. For the client to receive the information, the client must maintain a connection to the server. Streaming API uses the Bayeux protocol and CometD, so the client to server connection is maintained through long polling. Bayeux Protocol, CometD, and Long Polling Streaming API uses the Bayeux protocol and CometD for long polling. Bayeux is a protocol for transporting asynchronous messages, primarily over HTTP. CometD is a scalable HTTP-based event routing bus that uses an AJAX push technology pattern known as Comet. It implements the Bayeux protocol. Long polling, also called Comet programming, allows emulation of an information push from a server to a client. Similar to a normal poll, the client connects and requests information from the server. However, instead of sending an empty response if information isn't available, the server holds the request and waits until information is available (an event occurs). The server then sends a complete response to the client. The client then immediately re-requests information. The client continually maintains a connection to the server, so it s always waiting to receive a response. In the case of server timeouts, the client connects again and starts over. If you re not familiar with long polling, Bayeux, or CometD, review the CometD documentation. Streaming API supports the following CometD methods: Method connect disconnect handshake subscribe unsubscribe Description The client connects to the server. The client disconnects from the server. The client performs a handshake with the server and establishes a long polling connection. The client subscribes to a channel defined by a PushTopic. After the client subscribes, it can receive messages from that channel. You must successfully call the handshake method before you can subscribe to a channel. The client unsubscribes from a channel. Streaming API Terms Learn about terms used for Streaming API. Term Event Description The creation, update, delete, or undelete of a record. Each event might trigger a notification. 2

9 Introducing Streaming API How the Client Connects Term Notification PushTopic Description A message in response to an event. The notification is sent to a channel to which one or more clients are subscribed. A record that you create. The essential element of a PushTopic is the SOQL query. The PushTopic defines a Streaming API channel. How the Client Connects Streaming API uses the HTTP/1.1 request-response model and the Bayeux protocol (CometD implementation). A Bayeux client connects to Streaming API in multiple stages. 1. Sends a handshake request. 2. Sends a subscription request to a channel. 3. Connects using long polling. The maximum size of the HTTP request post body that the server can accept from the client is 32,768 bytes, for example, when you call the CometD subscribe or connect methods. If the request message exceeds this size, the following error is returned in the response: 413 Maximum Request Size Exceeded. To keep requests within the size limit, avoid sending multiple messages in a single request. The client receives events from the server while it maintains a long-lived connection. If the client receives events, it should reconnect immediately to receive the next set of events. If the reconnection doesn't occur within 40 seconds, the server expires the subscription and the connection closes. The client must start over with a handshake and subscribe again. If no events are generated and the client is waiting and the server closes the connection, after two minutes the client should reconnect immediately. If a long-lived connection is lost due to unexpected network disruption, CometD will automatically attempt to reconnect. If this reconnection is successful, clients must re-subscribe, since this new connection has gone through a re-handshake that removes previous subscribers. Clients can listen to the meta/handshake meta channel to receive notifications when a connection is lost and re-established. For details about these steps, see Bayeux Protocol, CometD, and Long Polling. Message Reliability As of API version 37.0, Streaming API provides reliable message delivery by enabling you to replay past events. In API version 36.0 and earlier, clients might not receive all messages in some situations. In API version 37.0 and later, Streaming API stores events for 24 hours, enabling you to replay past events. With durable streaming, messages aren t lost when a client is disconnected or isn t subscribed. When the client subscribes again, it can fetch past events that are within the 24-hour retention period. The ability to replay past events provides reliable message delivery. In API version 36.0 and earlier, Streaming API doesn t maintain client state nor keeps track of what s delivered. The client might not receive messages for several reasons, including: When a client first subscribes or reconnects, it might not receive messages that were processed while it wasn t subscribed to the channel. 3

10 Introducing Streaming API Message Durability When a client disconnects and starts a new handshake, it could be working with a different application server, so it receives only new messages from that point on. Some events are dropped when the system is being heavily used. If an application server is stopped, all messages being processed but not yet sent are lost. Clients connected to that application server are disconnected. To receive notifications, the client must reconnect and subscribe to the topic channel. Message Durability Salesforce stores events for 24 hours. With API version 37.0 and later, you can retrieve events that are within the retention window. The Streaming API event framework decouples event producers from event consumers. A subscriber can retrieve events at any time and isn t restricted to listening to events at the time they re sent. Event Replay Process Each event message is assigned an opaque ID contained in the ReplayId field. The ReplayId field value, which is populated by the system, refers to the position of the event in the event stream. Replay ID values are not guaranteed to be contiguous for consecutive events. For example, the event following the event with ID 999 can have an ID of 1,025. A subscriber can store a replay ID value and use it on resubscription to retrieve events that are within the retention window. For example, a subscriber can retrieve missed events after a connection failure. Subscribers must not compute new replay IDs based on a stored replay ID to refer to other events in the stream. This JSON message shows the replayid field in the event object for a generic event. { "clientid":"a1ps4wpe52qytvcvbsko09tapc", "data":{ "event":{ "createddate":" t19:05:28.334z", "replayid":55, "payload":"this is a message.", "channel":"/u/teststreaming" This JSON message shows the replayid field in the event object for a PushTopic event. { "clientid":"2t80j2hcog29sdh9ihjd9643a", "data":{ "event":{ "createddate":" t16:40:08.208z", "replayid":13, "type":"created", "sobject":{ "Website":null, "Id":"001D000000KnaXjIAJ", "Name":"TicTacToe", "channel":"/topic/testaccountstreaming" 4

11 Introducing Streaming API Message Durability Note: In API version 37.0 and later, the time format of the createddate field value has changed to make it consistent with the time format used in the Salesforce app. The time portion now ends with a Z suffix instead of Both suffixes denote a UTC time zone. Replaying Events A subscriber can choose which events to receive, such as all events within the retention window or starting after a particular event. The default is to receive only the new events sent after subscribing. Events outside the 24-hour retention period are discarded. This high-level diagram shows how event consumers can read a stream of events by using various replay options. Replay Option Replay ID -1-2 Table 1: Replay Options Description Subscriber receives all events after the event specified by its replayid value. Subscriber receives new events that are broadcast after the client subscribes. Subscriber receives all events, including past events that are within the 24-hour retention window and new events sent after subscription. To replay events, use the Streaming API endpoint. Note: Durable streaming is supported at this endpoint starting with API version Durable Generic Streaming is supported in version 36.0 at this alternative endpoint: However, we recommend you upgrade to version 37.0 and use the main Streaming API endpoint. The replay mechanism is implemented in a Salesforce-provided CometD extension. A sample extension is provided in JavaScript and another in Java. For example, you can register the extension as follows in JavaScript. // Register streaming extension var replayextension = new cometdreplayextension(); replayextension.setchannel(<streaming Channel to Subscribe to>); replayextension.setreplay(<event Replay Option>); cometd.registerextension('myreplayextensionname', replayextension); 5

12 Introducing Streaming API Message Durability Note: The argument passed to setreplay() is one of the replay options listed in Replay Options. We recommend that clients subscribe with the 1 option to receive new events or with a specific replay ID. If the channel contains many event messages, subscribing frequently with the 2 option can cause performance issues. The first argument passed to registerextension() is the name of the replay extension in your code. In the example, it s set to myextensionname, but it can be any string. You use this name to unregister the extension later on. If the setreplay() function isn t called, or the CometD extension isn t registered, only new events are sent to the subscriber, which is the same as the 1 option. After calling the setreplay() function on the extension, the events that the subscriber receives depend on the replay value parameter passed to setreplay(). After a client times out because it hasn t reconnected within 40 seconds or a network failure has occurred, it attempts a new handshake request and reconnects. The replay extension saves the replay ID of the last message received and uses it when resubscribing. That way, the client receives only messages that were sent after the timeout and doesn t receive duplicate messages that were sent earlier. Code Samples Visualforce Sample For a sample and code walkthrough that uses Visualforce and a CometD extension in JavaScript, see Example: Subscribe to and Replay Events Using a Visualforce Page Java Samples For a Java client sample that uses the CometD extension, see the Example: Subscribe to and Replay Events Using a Java Client SEE ALSO: Bayeux Protocol, CometD, and Long Polling Clients and Timeouts 6

13 CHAPTER 2 Quick Start Using Workbench This quick start shows you how to get started with Streaming API by using Workbench. This quick start takes you step-by-step through the process of using Streaming API to receive a notification when a record is updated. Prerequisites Step 1: Create an Object Step 2: Create a PushTopic Step 3: Subscribe to the PushTopic Channel Step 4: Test the PushTopic Channel Prerequisites You need access and appropriate permissions to complete the quick start steps. Access to a Developer Edition organization. If you are not already a member of the Force.com developer community, go to developer.salesforce.com/signup and follow the instructions for signing up for a Developer Edition organization. Even if you already have Enterprise Edition, Unlimited Edition, or Performance Edition, use Developer Edition for developing, staging, and testing your solutions against sample data to protect your organization s live data. This is especially true for applications that insert, update, or delete data (as opposed to simply reading data). The API Enabled permission must be enabled for your Developer Edition organization. This permission is enabled by default, but may have been changed by an administrator. The Streaming API permission must be enabled. Note: To verify that the API Enabled and Streaming API permissions are enabled in your organization, from Setup, enter User Interface in the Quick Find box, then select User Interface. The logged-in user must have Read permission on the PushTopic standard object to receive notifications. The logged-in user must have Create permission on the PushTopic standard object to create and manage PushTopic records. The logged-in user must have Author Apex permissions to create a PushTopic by using the Developer Console. Step 1: Create an Object The first step is to create an InvoiceStatement object. After you create a PushTopic and subscribe to it, you ll get notifications when an InvoiceStatement record is created, updated, deleted, or undeleted. You ll create the object with the user interface. 1. From your management settings for custom objects, if you re using Salesforce Classic, click New Custom Object, or if you re using Lightning Experience, select Create > Custom Object. 7

14 Quick Start Using Workbench Step 2: Create a PushTopic 2. Define the custom object. In the Label field, type Invoice Statement. In the Plural Label field, type Invoice Statements. Select Starts with vowel sound. In the Record Name field, type Invoice Number. In the Data Type field, select Auto Number. In the Display Format field, type INV-{0000. In the Starting Number field, type Click Save. 4. Add a Status field. a. Scroll down to the Custom Fields & Relationships related list and click New. b. For Data Type, select Picklist and click Next. c. In the Field Label field, type Status. d. Type the following picklist values in the box provided, with each entry on its own line. Open Closed Negotiating Pending e. Select the checkbox for Use first value as default value. f. Click Next. g. For field-level security, select Read Only and then click Next. h. Click Save & New to save this field and create a new one. 5. Now create an optional Description field. a. In the Data Type field, select Text Area and click Next. b. In the Field Label and Field Name fields, enter Description. c. Click Next, accept the defaults, and click Next again. d. Click Save to go the detail page for the Invoice Statement object. Your InvoiceStatement object should now have two custom fields. SEE ALSO: Salesforce Help: Find Object Management Settings Step 2: Create a PushTopic Use the Developer Console to create the PushTopic record that contains a SOQL query. Event notifications are generated for updates that match the query. Alternatively, you can also use Workbench to create a PushTopic. 1. Open the Developer Console. 8

15 Quick Start Using Workbench Step 3: Subscribe to the PushTopic Channel 2. Click Debug > Open Execute Anonymous Window. 3. In the Enter Apex Code window, paste in the following Apex code, and click Execute. PushTopic pushtopic = new PushTopic(); pushtopic.name = 'InvoiceStatementUpdates'; pushtopic.query = 'SELECT Id, Name, Status c, Description c FROM Invoice_Statement c'; pushtopic.apiversion = 41.0; pushtopic.notifyforoperationcreate = true; pushtopic.notifyforoperationupdate = true; pushtopic.notifyforoperationundelete = true; pushtopic.notifyforoperationdelete = true; pushtopic.notifyforfields = 'Referenced'; insert pushtopic; Note: If your organization has a namespace prefix defined, then you ll need to preface the custom object and field names with that namespace when you define the PushTopic query. For example, SELECT Id, Name, namespace Status c, namespace Description c FROM namespace Invoice_Statement c. Because NotifyForOperationCreate, NotifyForOperationUpdate, NotifyForOperationDelete and NotifyForOperationUndelete are set to true, Streaming API evaluates records that are created, updated, deleted, or undeleted and generates a notification if the record matches the PushTopic query. Because NotifyForFields is set to Referenced, Streaming API will use fields in both the SELECT clause and the WHERE clause to generate a notification. Whenever the fields Name, Status c, or Description c are updated, a notification will be generated on this channel. For more information about NotifyForOperationCreate, NotifyForOperationUpdate, NotifyForOperationDelete, NotifyForOperationUndelete, and NotifyForFields, see Event Notification Rules. Note: In API version 28.0 and earlier, notifications are only generated when records are created or updated. The NotifyForOperationCreate, NotifyForOperationUpdate, NotifyForOperationDelete, and NotifyForOperationUndelete fields are unavailable and the NotifyForOperations enum field is used instead to set which record events generate a notification. For more information see PushTopic. SEE ALSO: Salesforce Help: Open the Developer Console Step 3: Subscribe to the PushTopic Channel In this step, you subscribe to the channel that you created with the PushTopic record in the previous step. Important: Workbench is a free, open source, community-supported tool (see the Help page in Workbench). Salesforce provides a hosted instance of Workbench for demonstration purposes only Salesforce recommends that you do not use this hosted instance of Workbench to access data in a production database. If you want to use Workbench for your production database, you can download, host, and configure it using your own resources. You can download Workbench from 1. In your browser, navigate to 2. For Environment, select Production. 3. For API Version, select Note: Workbench supports Streaming API in versions 36.0 and earlier only. 9

16 Quick Start Using Workbench Step 4: Test the PushTopic Channel 4. Accept the terms of service, and click Login with Salesforce. 5. After you successfully establish a connection to your database, you land on the Select page. 6. Select queries > Streaming Push Topics. 7. In the Push Topic field, select InvoiceStatementUpdates. 8. Click Subscribe. You ll see the connection and response information and a response like Subscribed to /topic/invoicestatementupdates. Keep this browser window open and make sure that the connection doesn t time out. You ll be able to see the event notifications triggered by the InvoiceStatement record you create in the next step. Step 4: Test the PushTopic Channel Make sure the browser that you used in Step 3: Subscribe to the PushTopic Channel stays open and the connection doesn t time out. You ll view event notifications in this browser. The final step is to test the PushTopic channel by creating a new InvoiceStatement record in Workbench and viewing the event notification. 1. In a new browser window, open an instance of Workbench and log in using the same username by following the steps in Step 3: Subscribe to the PushTopic Channel. Note: If the user that makes an update to a record and the user that s subscribed to the channel don t share records, then the subscribed user won t receive the notification. For example, if the sharing model for the organization is private. 2. Click data > Insert. 3. For Object Type, select Invoice_Statement c. Ensure that the Single Record field is selected, and click Next. 4. Type in a value for the Description c field. 5. Click Confirm Insert. 6. Switch over to your Streaming Push Topics browser window. You ll see a notification that the invoice statement was created. The notification returns the Id, Status c, and Description c fields that you defined in the SELECT statement of your PushTopic query. The message looks something like this: { "channel": "/topic/invoicestatementupdates", "data": { "event": { "type": "created", "createddate": " T17:33: ", "sobject": { "Name": "INV-0004", "Id": "a00d oli8iae", "Description c": "Test invoice statement", "Status c": "Open" 10

17 CHAPTER 3 In this chapter... Example: Subscribe to and Replay Events Using a Visualforce Page Example: Interactive Visualforce Page without Replay Example: Subscribe to and Replay Events Using a Java Client Example: Authentication Code Examples Check out code examples for PushTopic and generic events in Visualforce and Java, and an authentication example. 11

18 Code Examples Example: Subscribe to and Replay Events Using a Visualforce Page Example: Subscribe to and Replay Events Using a Visualforce Page This sample app shows you how to subscribe to durable streaming events for PushTopic and generic events. The app contains two interactive Visualforce pages: one for PushTopic events and one for generic events. You can generate test events and view them on each page. You specify which events are retrieved and displayed by setting replay options. For each Visualforce page, the logic for replaying events is contained within a Visualforce component. The component registers the Salesforce-provided CometD extension and sets replay options. IN THIS SECTION: Prerequisites Set up permissions that are required to run the durable streaming samples. Deploy a Sample Project to Your Org Use Workbench to copy all project components to your org. Durable PushTopic Streaming Sample The Durable PushTopic Streaming Visualforce sample shows you how to use replay options to subscribe and receive durable PushTopic event notifications. Durable Generic Streaming Sample The Durable Generic Streaming Visualforce sample shows you how to use replay options to subscribe and receive durable generic event notifications. Replay Events Sample: Code Walkthrough Learn how to register and use the CometD replay extension in JavaScript. Prerequisites Set up permissions that are required to run the durable streaming samples. You must have access to a Developer Edition org and have the API Enabled and Streaming API permissions enabled. The API Enabled permission is enabled by default, but an administrator might have changed it. If you are not already a member of the Force.com developer community, go to developer.salesforce.com/signup and follow the instructions for signing up for a Developer Edition organization. Even if you already have Enterprise Edition, Unlimited Edition, or Performance Edition, use Developer Edition for developing, staging, and testing your solutions against sample data to protect your organization s live data. This is especially true for applications that insert, update, or delete data (as opposed to simply reading data). Note: To verify that the API Enabled and Streaming API permissions are enabled in your organization, from Setup, enter User Interface in the Quick Find box, then select User Interface. To receive notifications, the logged-in user must have Read permission on the StreamingChannel standard object. To create and manage notifications, the logged-in user must have Create permission on the StreamingChannel standard object. To save the Apex class, the logged-in user must have the Author Apex permission. To save the Visualforce page, the logged-in user must have the Customize Application permission. Deploy a Sample Project to Your Org Use Workbench to copy all project components to your org. 12

19 Code Examples Deploy a Sample Project to Your Org 1. Download the Salesforce Durable Streaming Demo.zip file from the developerforce github repository. If you want, you can browse the contents of the project at The sample app contains two Visualforce pages with related components and some common components. The following common components are installed in your org when you deploy the.zip file. Component cometdreplayextension cometd, jquery, jquery_cometd, json2 Description Static resource representing a CometD extension in JavaScript. This extension implements the replay mechanism for Streaming API. Static resources for CometD 3.1.0, jquery, and JSON. The following app components are for the Durable PushTopic Streaming page. Component DurablePushTopicEventDisplay DurablePushTopicStreamingController DurablePushTopicStreamingDemo Visualforce Page Description A Visualforce component that uses the CometD extension cometdreplayextension to replay events. The extension handles the handshake and subscribe calls and sets replay options. Having the replay functionality in a Visualforce component allows you to add it to your Visualforce page for reuse in your app. Apex controller that holds the logic behind the Visualforce page. Visualforce page. This page is the main page you use to generate, view, and replay durable PushTopic events. The following app components are for the Durable Generic Streaming page. Component DurableGenericEventDisplay DurableGenericStreamingController StreamingChannel DurableGenericStreamingDemo Visualforce Page DurableStreamingDemo Permission Set Description A Visualforce component that uses the CometD extension cometdreplayextension to replay events. The extension handles the handshake and subscribe calls and sets replay options. Having the replay functionality in a Visualforce component allows you to add it to your Visualforce page for reuse in your app. Apex controller that holds the logic behind the Visualforce page. Custom object used for creating streaming channels. Visualforce page. This page is the main page you use to generate, view, and replay durable generic events. Permission set used to grant read and create access to the StreamingChannel sobject. 13

20 Code Examples Assign a Permission Set You use Workbench to migrate the zip file to your org. 2. Log in to Workbench at Important: Workbench is a free, open source, community-supported tool (see the Help page in Workbench). Salesforce provides a hosted instance of Workbench for demonstration purposes only Salesforce recommends that you do not use this hosted instance of Workbench to access data in a production database. If you want to use Workbench for your production database, you can download, host, and configure it using your own resources. You can download Workbench from 3. For Environment, keep the production default value. 4. Ensure that the value for API Version is at least Accept the service terms, and then click Login with Salesforce. 6. Enter your Developer Edition org username and password, and then click Log In. 7. Select migration > Deploy. 8. Click Choose File and locate the.zip file that you downloaded. 9. Click Next, and then click Deploy. 10. Wait until the deployment finishes and the status of the deployment changes to Succeeded. 11. Log in to your org in another browser tab. SEE ALSO: GitHub: Streaming Replay Client Extensions Assign a Permission Set 1. From Setup, enter Permission Sets in the Quick Find box, then select Permission Sets. 2. Click DurableStreamingDemo, and then click Manage Assignments. 3. Click Add Assignments. 4. Click the checkbox next to the user who is running the sample, and then click Assign. 5. Click Done. Durable PushTopic Streaming Sample The Durable PushTopic Streaming Visualforce sample shows you how to use replay options to subscribe and receive durable PushTopic event notifications. Use a Visualforce Page to Generate and Replay PushTopic Events In this step, you use a Visualforce page to generate your own PushTopic streaming events and replay those events by using different options. When the Visualforce page is loaded, it creates a PushTopic for the Account object. The page also subscribes to this topic to receive notifications for account creations, updates, and deletions, with an option to replay events. You can specify the name of the account to create, update, and delete on the Visualforce page. These operations generate event notifications, which are displayed in the Notifications 14

21 Code Examples Durable PushTopic Streaming Sample section. You can control which events are received and displayed by subscribing with replay options. After generating events, you can replay events starting from: All events after a particular event specified by a replay ID. The first event broadcast right after subscribing (replay option -1). The earliest retained event in your org that s less than 24 hours old (replay option -2). The sample uses replay option -2 as the default option. This Visualforce sample is part of the Durable Streaming Demo app. 1. Open the Durable Streaming Demo app. 2. Click the Durable PushTopic Streaming Demo tab. The Visualforce page loads and subscribes to the PushTopic it created for the Account object. 3. On the Visualforce page, generate some events for an account. For example, Test account. 4. Click Create, Update, Delete New Account. Note: The page subscribes to all new and old events by default (-2). The page first displays debug information about the CometD connection in the Notifications section followed by the events received. The first time you generate events, there are no stored events, and you see only the new events. 5. To change the point in time when events are read, enter the replay ID to read from in the Replay From Id field. For example, to read all events after the event with replay ID 2, enter 2. Then click Update Subscription. The Notifications section is updated and shows only the last event with replay ID To receive only the events that are sent after you subscribe, enter -1 in the Replay From ID field. Then click Update Subscription. The Notifications section is cleared, because only new events from this point on are shown. 7. Generate some new events like you did previously using Lightning for the account name. The Notifications section is updated with the new events and doesn t show the old events. 15

22 Code Examples Durable PushTopic Streaming Sample 8. Switch the replay option back to -2. The page displays all events, including events that were sent earlier. 16

23 Code Examples Durable Generic Streaming Sample Durable Generic Streaming Sample The Durable Generic Streaming Visualforce sample shows you how to use replay options to subscribe and receive durable generic event notifications. Create a Streaming Channel You must have the appropriate Streaming API permissions enabled in your org. Create a StreamingChannel object by using the Salesforce UI. 1. Log in to your Developer Edition org. 2. If you re using Salesforce Classic, under All Tabs (+), select Streaming Channels. If you re using Lightning Experience, from the App Launcher, select All Items, and then click Streaming Channels. 3. On the Streaming Channels page, click New to create a streaming channel. 4. Enter /u/teststreaming in Streaming Channel Name and add an optional description. Your new Streaming Channel page looks something like this: 17

24 Code Examples Durable Generic Streaming Sample 5. Click Save. You now have a streaming channel that clients can subscribe to for notifications. StreamingChannel is a regular, creatable Salesforce object, so you can also create one programmatically using Apex or a data API like the SOAP API or REST API, or using a tool such as Workbench. For more information, see StreamingChannel. Use a Visualforce Page to Generate and Replay Generic Events In this step, you use a Visualforce page to generate your own streaming events and replay those events by using different options. The Visualforce page simulates a streaming client that subscribes to events with options to replay events. The Visualforce page allows you to supply the event s message and specify the number of messages to create. The page listens to events and displays the received events in the Notifications section. After generating events, you can replay events starting from: All events after a particular event specified by a replay ID. The first event broadcast right after subscribing (replay option -1). The earliest retained event in your org that s less than 24 hours old (replay option -2). The sample uses replay option -2 as the default option. This Visualforce sample is part of the Durable Streaming Demo app. 1. Open the Durable Streaming Demo app. 2. Click the Durable Generic Streaming Demo tab. The Visualforce page loads and subscribes to the test channel you created earlier. 3. In the Visualforce page, generate some events. Enter any text for the message text, for example, Test message. For Number of Events, enter Click Generate. Note: The page subscribes to all events by default (-2). The page first displays debug information about the CometD connection in the Notifications section followed by the events received. The first time you generate events, there are no stored events, and you see only the new events. 5. To change the point in time when events are read, enter the replay ID to read from in the Replay From Id field. For example, to read all events after the event with replay ID 5, enter 5. Then click Update Subscription. The Notifications section is updated and shows only the last five events starting from replay ID 6. 18

25 Code Examples Durable Generic Streaming Sample 6. To receive only the events that are sent after you subscribe, enter -1 in the Replay From Id field. Then click Update Subscription. The Notifications section is cleared, because only new events from this point on are shown. 7. Generate some new events like you did in step 3 with New events for the message. The Notifications section is updated with the new events and doesn t show the old events. 19

26 Code Examples Durable Generic Streaming Sample 8. Switch the replay option back to -2. The page displays all events, including events that were sent earlier. 20

27 Code Examples Replay Events Sample: Code Walkthrough Replay Events Sample: Code Walkthrough Learn how to register and use the CometD replay extension in JavaScript. JavaScript Sample for Replaying Events The Visualforce components in the durable streaming sample implement a CometD client that subscribes with replay options. The components are embedded in Visualforce pages. For generic events, the Visualforce component is DurableGenericEventDisplay. For PushTopic events, the Visualforce component is DurablePushTopicEventDisplay. If you want to implement a CometD client with replay options, you can reuse the Visualforce components or adapt the JavaScript code for your app. Portions of the sample component are highlighted in this section. The first step is to register the Salesforce-provided CometD extension cometdreplayextension to replay events. This snippet also sets the streaming channel and the replay option. The first argument in registerextension is an arbitrary name, which you use to unregister the extension. // Register Generic Streaming Replay extension var replayextension = new cometdreplayextension(); 21

28 Code Examples Replay Events Sample: Code Walkthrough replayextension.setchannel(<streaming Channel to Subscribe to>); replayextension.setreplay(<event Replay Option>); cometd.registerextension('myreplayextensionname', replayextension); Next, the client connects to the CometD replay endpoint. The API version in the endpoint must be 37.0 or later. The session ID value of the current session is passed in the Authorization header. The client calls the cometd configure() function to set up the connection and specify the endpoint and authorization header. Next, the client performs a handshake by calling cometd handshake() function. // Connect to the CometD endpoint cometd.configure({ url: window.location.protocol+'//'+window.location.hostname+ (null!= window.location.port? (':'+window.location.port) : '') + '/cometd/37.0/', requestheaders: { Authorization: 'OAuth {!$Api.Session_ID' ); cometd.handshake(); To ensure that every step in the connection process is successful before moving on to the next step, the client uses listeners. For example, a listener for the /meta/handshake channel checks whether the handshake is successful. If it is successful, the subscribe() function is called. if(!metahandshakelistener) { metahandshakelistener = cometd.addlistener('/meta/handshake', function(message) { if (message.successful) { $('#content').append('<br><br> DEBUG: Handshake Successful: '+ JSON.stringify(message)+' <br><br>'); ); if (message.ext && message.ext[replay_from_key] == true) { isextensionenabled = true; subscribedtochannel = subscribe(channel); else $('#content').append('debug: Handshake Unsuccessful: '+ JSON.stringify(message)+' <br><br>'); The last step is to specify a callback for the CometD subscribe() function. CometD calls this callback function when a message is received in the channel. In this sample, the callback function displays the message data to the page. It appends the data to the div HTML element whose ID value is "content". function subscribe(channel) { // Subscribe to a topic. // JSON-encoded update will be returned in the callback. return cometd.subscribe(channel, function(message) { var div = document.getelementbyid('content'); div.innerhtml = div.innerhtml + '<p>notification ' + 'on channel: ' + JSON.stringify(message.channel) + '<br>' + 'Payload: ' + JSON.stringify(message.data.payload) + '<br>' + 'Replay Id: ' + JSON.stringify(message.data.event.replayId) + '<br>' + 'Full message: ' + JSON.stringify(message) + '</p><br>'; ); 22

29 Code Examples Example: Interactive Visualforce Page without Replay cometdreplayextension Extension Note: The extension is a prerequisite for the replay functionality in a CometD client. In the durable streaming sample, the Visualforce components register and use the extension. If you implement a CometD client, include the replay extension in your project, but you don t have to modify it. The cometdreplayextension contains cometd extension functions that are called for incoming and outgoing messages. These extension functions implement the logic that checks for the extension s registration on handshake and sets the replay option on subscription. On handshake, the function for incoming messages checks whether the replay extension has been registered. If so, it sets the _extensionenabled variable to true. This function also saves the replay ID of the received message so that it can be used when a client reconnects after a timeout. this.incoming = function(message) { if (message.channel === '/meta/handshake') { if (message.ext && message.ext[replay_from_key] == true) { _extensionenabled = true; else if (message.channel === _channel && message.data && message.data.event && message.data.event.replayid) { _replay = message.data.event.replayid; On subscription, the function for outgoing messages checks whether the replay extension has been registered by inspecting the _extensionenabled variable. If the extension is registered, the function subscribes to events based on the specified replay option. The sample sets the replay option by calling the extension s setreplay() function. this.outgoing = function(message) { if (message.channel === '/meta/subscribe') { if (_extensionenabled) { if (!message.ext) { message.ext = {; var replayfrommap = {; replayfrommap[_channel] = _replay; // add "ext : { "replay" : { CHANNEL : REPLAY_VALUE " // to subscribe message. message.ext[replay_from_key] = replayfrommap; ; Example: Interactive Visualforce Page without Replay This code example shows you how to implement Streaming API from a Visualforce page. The sample uses the Dojo library and CometD to subscribe to PushTopic events. On the Visualforce page, you enter the name of the PushTopic channel you want to subscribe to and click Subscribe to receive notifications on the page. Click Unsubscribe to unsubscribe from the channel and stop receiving notifications. Note: This sample doesn t use the replay extension and can t receive past events. To use a replay option, check out Example: Subscribe to and Replay Events Using a Visualforce Page. 23

30 Code Examples Prerequisites IN THIS SECTION: Prerequisites You need access and appropriate permissions to complete the code example. Step 1: Create an Object Step 2: Create a PushTopic Step 3: Create the Static Resources Step 4: Create a Visualforce Page Step 5: Test the PushTopic Channel Prerequisites You need access and appropriate permissions to complete the code example. Access to a Developer Edition organization. If you are not already a member of the Force.com developer community, go to developer.salesforce.com/signup and follow the instructions for signing up for a Developer Edition organization. Even if you already have Enterprise Edition, Unlimited Edition, or Performance Edition, use Developer Edition for developing, staging, and testing your solutions against sample data to protect your organization s live data. This is especially true for applications that insert, update, or delete data (as opposed to simply reading data). The API Enabled permission must be enabled for your Developer Edition organization. This permission is enabled by default, but may have been changed by an administrator. The Streaming API permission must be enabled. Note: To verify that the API Enabled and Streaming API permissions are enabled in your organization, from Setup, enter User Interface in the Quick Find box, then select User Interface. The logged-in user must have Read permission on the PushTopic standard object to receive notifications. The logged-in user must have Create permission on the PushTopic standard object to create and manage PushTopic records. The logged-in user must have Author Apex permissions to create a PushTopic by using the Developer Console. Step 1: Create an Object To perform this example, you must first create the InvoiceStatement object. If you haven t already created this object, see Step 1: Create an Object. Step 2: Create a PushTopic To perform this example, you must create a PushTopic. If you haven t already done so, see Step 2: Create a PushTopic. Step 3: Create the Static Resources 1. Download this static resource.zip file: streaming_api_interactive_visualforce_demo-v40.zip 2. Extract the following files from the.zip fle: 24

31 Code Examples Step 4: Create a Visualforce Page File Name cometd.zip demo.css demo.js json2.js StreamingApiDemo Description Files for CometD version and the Dojo toolkit used by demo.js. When you define a.zip archive file as a static resource, Visualforce can access the files in that archive. The.zip file becomes a virtual file system. The CSS code that formats the Visualforce page. The code used by the page to subscribe to the channel, receive and display the notifications, and unsubscribe from the channel. The JavaScript library that contains the stringify and parse methods. The Visualforce page that displays the Streaming API notifications. 3. From Setup, enter Static Resources in the Quick Find box, then select Static Resources to add the extracted files with the following names: File Name cometd.zip demo.css demo.js json2.js Static Resource Name cometd_zip demo_css demo_js json2_js For more information about static resources, see Deliver Static Resources with Visualforce. Step 4: Create a Visualforce Page Create a Visualforce page to display the channel notifications. 1. From Setup, enter Visualforce Pages in the Quick Find box, then select Visualforce Pages. 2. Click New. 3. In the Label field, enter the name of the page StreamingAPIDemo. 4. Replace the code in the page with the code from the StreamingApiDemo file that you downloaded. <apex:page > <apex:includescript value="{!$resource.json2_js"/> <script type="text/javascript" src="{!urlfor($resource.cometd_zip, 'dojo/dojo.js')" data-dojo-config="async: 1"></script> <apex:stylesheet value="{!$resource.demo_css"/> <script>var token = '{!$Api.Session_ID';</script> <div id="demo"> <div id="datastream"></div> <script type="text/javascript" src="{!$resource.demo_js"> </script> <div id="input"> 25

32 Code Examples Step 5: Test the PushTopic Channel <div id="join"> <table> <tbody> <tr> <td> </td> <td> Enter Topic Name </td> <td> <input id="topic" type="text" /> </td> <td> <button id="subscribebutton" class="button">subscribe</button> </td> </tr> </tbody> </table> </div> <div id="joined"> <table> <tbody> <tr> <td> <button id="leavebutton" class="button">unsubscribe</button> </td> </tr> </tbody> </table> </div> </div> </div> </apex:page> 5. Click Save to save the page. Step 5: Test the PushTopic Channel 1. To load the Visualforce page in a web browser, click Preview on the Visualforce page editor: 2. In the text box, enter the channel name: /topic/invoicestatementupdates. 3. To subscribe to the channel, click Subscribe. 4. Create or modify an InvoiceStatement in a different browser tab. The page displays some debug messages and event notifications. The output resembles the following: DEBUG: Handshake Successful: { "ext":{"replay":true,"payload.format":true, "minimumversion":"1.0", "clientid":"41kdiuvgig2tfxdh9weakuiwyh", "supportedconnectiontypes":["long-polling"], "channel":"/meta/handshake", "id":"1","version":"1.0","successful":true,"reestablish":false DEBUG: Connection Successful : { 26

33 Code Examples Example: Subscribe to and Replay Events Using a Java Client "clientid":"41kdiuvgig2tfxdh9weakuiwyh", "advice":{ "interval":2000,"multiple-clients":true,"reconnect":"retry", "timeout":110000,"channel":"/meta/connect","id":"2", "successful":true DEBUG: Subscribe Successful /topic/invoicestatementupdates: {"clientid":"41kdiuvgig2tfxdh9weakuiwyh","channel":"/meta/subscribe", "id":"15","subscription":"/topic/invoicestatementupdates","successful":true { "event": { "createddate": " T23:05:50.173Z", "replayid": 1, "type": "created", "sobject": { "Description c": "New invoice.", "Id": "a00d ybwqias", "Status c": "Open", "Name": "INV-0001" { "event": { "createddate": " T23:06:11.529Z", "replayid": 2, "type": "updated", "sobject": { "Description c": "New invoice.", "Id": "a00d ybwqias", "Status c": "Negotiating", "Name": "INV-0001" The debug messages contain information about the subscription status. The first event notification shows the notification data when an invoice statement is created. The second notification shows the notification data when an invoice statement is updated. Click Unsubscribe to unsubscribe from the channel and stop receiving notifications. Example: Subscribe to and Replay Events Using a Java Client This code example implements Streaming API from a Java client using a library called Enterprise Messaging Platform (EMP) Connector. EMP connector is a thin wrapper around the CometD library. It hides the complexity of creating a CometD client and subscribing to Streaming API in Java. The example subscribes to a channel, receives notifications, and supports replaying events with durable streaming. 27

34 Code Examples Prerequisites Important: EMP Connector is a free, open-source, community-supported tool. Salesforce provides this tool as an example of how to subscribe to events using CometD. To contribute to the EMP Connector project with your own enhancements, submit pull requests to the repository at EMP Connector is based on Java 8 and uses CometD version The connector supports PushTopic and generic streaming. It also supports username and password authentication and OAuth bearer token authentication. Note: The example requires API version 37.0 or later. For a code example that supports earlier API versions, refer to an earlier version of this documentation. IN THIS SECTION: Prerequisites You need access and appropriate permissions to complete the code example. Step 1: Create an Object Step 2: Create a PushTopic Step 3: Download and Build the Project Before you can run the connector examples, download the Java source files and build the Java project. Step 4: Use the Connector with Username and Password Login Now that you ve downloaded and built the EMP connector, use its functions to connect to CometD and subscribe to the PushTopic. Step 5: Use the Connector with OAuth Bearer Token Login This step uses the connector with OAuth authentication as an alternative to username and password authentication. This step is optional and requires an OAuth token. Learn More About EMP Connector Let s take a closer look at the components of EMP Connector. Prerequisites You need access and appropriate permissions to complete the code example. Java Development Kit 8. See Java Downloads. Eclipse IDE for Java Developers. Download a recent version from Access to a Developer Edition organization. If you are not already a member of the Force.com developer community, go to developer.salesforce.com/signup and follow the instructions for signing up for a Developer Edition organization. Even if you already have Enterprise Edition, Unlimited Edition, or Performance Edition, use Developer Edition for developing, staging, and testing your solutions against sample data to protect your organization s live data. This is especially true for applications that insert, update, or delete data (as opposed to simply reading data). The API Enabled permission must be enabled for your Developer Edition organization. This permission is enabled by default, but may have been changed by an administrator. The Streaming API permission must be enabled. Note: To verify that the API Enabled and Streaming API permissions are enabled in your organization, from Setup, enter User Interface in the Quick Find box, then select User Interface. The logged-in user must have Read permission on the PushTopic standard object to receive notifications. The logged-in user must have Create permission on the PushTopic standard object to create and manage PushTopic records. 28

35 Code Examples Step 1: Create an Object The logged-in user must have Author Apex permissions to create a PushTopic by using the Developer Console. Step 1: Create an Object To perform this example, you must first create the InvoiceStatement object. If you haven t already created this object, see Step 1: Create an Object. Step 2: Create a PushTopic To perform this example, you must create a PushTopic. If you haven t already done so, see Step 2: Create a PushTopic. Step 3: Download and Build the Project Before you can run the connector examples, download the Java source files and build the Java project. Prerequisites: Java Development Kit 8. See Java Downloads. Eclipse IDE for Java Developers. Download a recent version from The EMP connector project includes examples under the GitHub repository s example folder that use the connector to log in and subscribe to events. In the next steps, you run the following examples locally on your system. LoginExample.java BearerTokenExample.java To download and build the EMP connector project: 1. To download the project files, do one of the following. a. Clone the EMP-Connector project using git. git clone b. Download the project zip file from GitHub, and then extract the zip to a local folder. 2. In Eclipse, import the Maven project from the folder where you cloned or extracted the project. The dependencies that are specified in the Maven s pom.xml file, such as CometD, are added in the Java project in Eclipse. 3. If the Java project wasn t automatically built, build it. Note: If you prefer to run the tool from the command line, generate the JAR file using the Maven command: mvn clean package. After you run this command, a JAR file is generated that includes the connector and the LoginExample functionality. The JAR file is a shaded JAR it contains all the dependencies for the connector so you don t have to download them separately. The JAR file has a -phat Maven classifier. You can run the login example from the command line, as follows. java -jar emp-connector snapshot-phat.jar <username> <password> <topic> [optional_replayid] EMP Connector is an open-source project, which means that you can contribute to it with your own enhancements by submitting pull requests to the repository. 29

36 Code Examples Step 4: Use the Connector with Username and Password Login Step 4: Use the Connector with Username and Password Login Now that you ve downloaded and built the EMP connector, use its functions to connect to CometD and subscribe to the PushTopic. Let s run an example that uses username and password login. 1. Under the /src/main/java/ folder, open the LoginExample.java Java source file from the example package folder. /* * Copyright (c) 2016, salesforce.com, inc. * All rights reserved. * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.TXT file in the repo root or */ package com.salesforce.emp.connector.example; import static com.salesforce.emp.connector.loginhelper.login; import java.util.map; import java.util.concurrent.timeunit; import java.util.function.consumer; import com.salesforce.emp.connector.bayeuxparameters; import com.salesforce.emp.connector.empconnector; import com.salesforce.emp.connector.topicsubscription; /** * An example of using the EMP connector using login credentials * hal.hildebrand */ public class LoginExample { public static void main(string[] argv) throws Exception { if (argv.length < 3 argv.length > 4) { System.err.println("Usage: LoginExample username password topic [replayfrom]"); System.exit(1); long replayfrom = EmpConnector.REPLAY_FROM_EARLIEST; if (argv.length == 4) { replayfrom = Long.parseLong(argv[3]); BayeuxParameters params; try { params = login(argv[0], argv[1]); catch (Exception e) { e.printstacktrace(system.err); System.exit(1); throw e; Consumer<Map<String, Object>> consumer = event -> System.out.println( String.format("Received:\n%s", event)); EmpConnector connector = new EmpConnector(params); 30

37 Code Examples Step 5: Use the Connector with OAuth Bearer Token Login connector.start().get(5, TimeUnit.SECONDS); TopicSubscription subscription = connector.subscribe(argv[2], replayfrom, consumer).get(5, TimeUnit.SECONDS); System.out.println(String.format("Subscribed: %s", subscription)); 2. Run the LoginExample class and provide the following argument values. Argument username password topic Value Username of the logged-in user. Password for the username (or logged-in user). /topic/invoicestatementupdates The sample fetches the earliest saved events within the past 24 hours. Optionally, you can supply a replay ID as the last argument to receive different events. Valid values are: -1 Get all new events sent after subscription. -2 Get all new events sent after subscription and all past events within the last 24 hours. Specific number Get all events that occurred after the event with the specified replay ID. 3. In a browser window, create or modify an invoice statement. After you create or change data that corresponds to the query in your PushTopic, the output looks similar to the following. Subscribed: Subscription [/topic/invoicestatementupdates:-2] Received: {event={createddate= t22:31:48.035z, replayid=1, type=created, sobject={status c=open, Id=a070P00000pn0hyQAA, Name=INV-0001, Description c=blah Received: {event={createddate= t22:32:06.440z, replayid=2, type=updated, sobject={status c=negotiating, Id=a070P00000pn0hyQAA, Name=INV-0001, Description c=blah Received: {event={createddate= t22:32:57.404z, replayid=3, type=created, sobject={status c=open, Id=a070P00000pn0lfQAA, Name=INV-0002, Description c=laptops and accessories. Generally, do not handle usernames and passwords of others when running code in production. In a production environment, delegate the login to OAuth. The next step connects to Streaming API with OAuth. Step 5: Use the Connector with OAuth Bearer Token Login This step uses the connector with OAuth authentication as an alternative to username and password authentication. This step is optional and requires an OAuth token. Prerequisites 31

38 Code Examples Step 5: Use the Connector with OAuth Bearer Token Login Obtain an OAuth bearer access token for your Salesforce user. You supply this access token in the connector example. See Set Up Authentication with OAuth 2.0. Also, see Authenticate Apps with OAuth in Salesforce Help and Understanding Authentication in the Force.com REST API Developer Guide. Let s run an example that uses OAuth bearer token login. 1. Under the /src/main/java/ folder, open the BearerTokenExample.java Java source file from the example package folder. /* * Copyright (c) 2016, salesforce.com, inc. All rights reserved. Licensed under the BSD 3-Clause license. For full * license text, see LICENSE.TXT file in the repo root or */ package com.salesforce.emp.connector.example; import java.net.malformedurlexception; import java.net.url; import java.util.map; import java.util.concurrent.timeunit; import java.util.function.consumer; import com.salesforce.emp.connector.bayeuxparameters; import com.salesforce.emp.connector.empconnector; import com.salesforce.emp.connector.topicsubscription; /** * An example of using the EMP connector using bearer tokens * hal.hildebrand */ public class BearerTokenExample { public static void main(string[] argv) throws Exception { if (argv.length < 2 argv.length > 4) { System.err.println( "Usage: BearerTokenExample url token topic [replayfrom]"); System.exit(1); long replayfrom = EmpConnector.REPLAY_FROM_EARLIEST; if (argv.length == 4) { replayfrom = Long.parseLong(argv[3]); BayeuxParameters params = new BayeuxParameters() public String bearertoken() { return public URL host() { try { return new URL(argv[0]); 32

39 Code Examples Step 5: Use the Connector with OAuth Bearer Token Login ; catch (MalformedURLException e) { throw new IllegalArgumentException( String.format("Unable to create url: %s", argv[0]), e); Consumer<Map<String, Object>> consumer = event -> System.out.println( String.format("Received:\n%s", event)); EmpConnector connector = new EmpConnector(params); connector.start().get(5, TimeUnit.SECONDS); TopicSubscription subscription = connector.subscribe(argv[2], replayfrom, consumer).get(5, TimeUnit.SECONDS); System.out.println(String.format("Subscribed: %s", subscription)); 2. Run the BearerTokenExample class, and provide the following argument values. Argument url token topic Value The URL of the Salesforce instance of the logged-in user. The access token returned by the OAuth authentication flow. /topic/invoicestatementupdates The sample fetches the earliest saved events within the past 24 hours. Optionally, you can supply a replay ID as the last argument to receive different events. Valid values are: -1 Get all new events sent after subscription. -2 Get all new events sent after subscription and all past events within the last 24 hours. Specific number Get all events that occurred after the event with the specified replay ID. 3. In a browser window, create or modify an invoice statement. After you create or change data that corresponds to the query in your PushTopic, the output looks similar to the following. Subscribed: Subscription [/topic/invoicestatementupdates:-2] Received: {event={createddate= t22:31:48.035z, replayid=1, type=created, sobject={status c=open, Id=a070P00000pn0hyQAA, Name=INV-0001, Description c=blah Received: {event={createddate= t22:32:06.440z, replayid=2, type=updated, sobject={status c=negotiating, Id=a070P00000pn0hyQAA, Name=INV-0001, Description c=blah Received: {event={createddate= t22:32:57.404z, replayid=3, type=created, sobject={status c=open, Id=a070P00000pn0lfQAA, Name=INV-0002, Description c=laptops and accessories. 33

40 Code Examples Learn More About EMP Connector Learn More About EMP Connector Let s take a closer look at the components of EMP Connector. Authenticating User credential information is passed in to the login function. The login function s return value is passed in to the main connector class later. BayeuxParameters params = login("<username>", "<password>"); For OAuth authentication, use the BayeuxParameters constructor to override the methods in the BayeuxParameters class and provide the token and URL values. BayeuxParameters params = new BayeuxParameters() public String bearertoken() { return "<token>"; public URL host() { try { return new URL("<URL>"); catch (MalformedURLException e) { throw new IllegalArgumentException( String.format("Unable to create url: %s", argv[0]), e); Listening to Events To listen to events, the connector uses the Java event in a lambda expression. This statement prints the event message to the output for each received event notification. Place this statement before the statement that subscribes to the topic. Consumer<Map<String, Object>> consumer = event -> System.out.println( String.format("Received:\n%s", event)); Subscribing to a Topic The EmpConnector class is the main class that exposes the functionality of starting a connection and subscribing. The class contains functions to create a connection, subscribe to a topic, cancel a subscription, and stop a connection. // Instantiate the EMP connector EmpConnector connector = new EmpConnector(params); // Wait for handshake with Streaming API connector.start().get(5, TimeUnit.SECONDS); // Subscribe to a topic // Block and wait for the subscription to succeed for 5 seconds 34

41 Code Examples Example: Authentication TopicSubscription subscription = connector.subscribe("/topic/mytopic", replayfrom, consumer).get(5, TimeUnit.SECONDS); To end a subscription, call these functions. // Cancel a subscription subscription.cancel(); // Stop the connector connector.stop(); Example: Authentication You can set up a simple authentication scheme for developer testing. For production systems, use robust authorization, such as OAuth 2.0. IN THIS SECTION: Set Up Authentication for Developer Testing Set Up Authentication with OAuth 2.0 Set Up Authentication for Developer Testing To set up authorization for developer testing: Important: This authorization method is simple to use and recommended for testing your code quickly. However, we recommend that you use OAuth 2.0 in a production environment for more robust security. The OAuth authentication method with a connected app provides restricted access and other benefits. 1. Log in using the SOAP API login() and get the session ID. 2. Set up the HTTP authorization header using this session ID: Authorization: Bearer sessionid The CometD endpoint requires a session ID on all requests, plus any additional cookies set by the Salesforce server. For more information, see Step 4: Use the Connector with Username and Password Login. Set Up Authentication with OAuth 2.0 Setting up OAuth 2.0 requires some configuration in the user interface and in other locations. If any of the steps are unfamiliar, you can consult the Force.com REST API Developer Guide or OAuth 2.0 documentation. The sample Java code in this chapter uses the Apache HttpClient library which may be downloaded from 1. In Salesforce Classic, from Setup, enter Apps in the Quick Find box, then select Apps. Or in Lightning Experience, enter App in the Quick Find box, then select App Manager. Click New in the Connected Apps related list to create a new connected app. The Callback URL you supply here is the same as your Web application's callback URL. Usually it s a servlet if you work with Java. It must be secure: doesn t work, only For development environments, the callback URL is similar to 35

42 Code Examples Set Up Authentication with OAuth When you click Save, the Consumer Key is created and displayed, and a Consumer Secret is created (click the link to reveal it). Note: The OAuth 2.0 specification uses client instead of consumer. Salesforce supports OAuth 2.0. The values here correspond to the following values in the sample code in the rest of this procedure: client_id is the Consumer Key client_secret is the Consumer Secret redirect_uri is the Callback URL. An additional value you must specify is: the grant_type. For OAuth 2.0 callbacks, the value is authorization_code as shown in the sample. For more information about these parameters, see If the value of client_id (or consumer key) and client_secret (or consumer secret) are valid, Salesforce sends a callback to the URI specified in redirect_uri that contains a value for access_token. 2. From your Java or other client application, make a request to the authentication URL that passes in grant_type, client_id, client_secret, username, and password. For example: HttpClient httpclient = new DefaultHttpClient(); HttpPost post = new HttpPost(baseURL); List<BasicNameValuePair> parametersbody = new ArrayList<BasicNameValuePair>(); parametersbody.add(new BasicNameValuePair("grant_type", password)); parametersbody.add(new BasicNameValuePair("client_id", clientid)); parametersbody.add(new BasicNameValuePair("client_secret", client_secret)); parametersbody.add(new BasicNameValuePair("username", parametersbody.add(new BasicNameValuePair("password", "swordfish")); Important: This method of authentication should only be used in development environments and not for production code. Example: This example gets the session ID (authenticates), and then follows a resource, contained in the first response to get more information about the user. public static void oauthsessionprovider(string loginhost, String username, String password, String clientid, String secret) throws HttpException, IOException { // Set up an HTTP client that makes a connection to REST API. DefaultHttpClient client = new DefaultHttpClient(); HttpParams params = client.getparams(); HttpClientParams.setCookiePolicy(params, CookiePolicy.RFC_2109); params.setparameter(httpconnectionparams.connection_timeout, 30000); // Set the SID. System.out.println("Logging in as " + username + " in environment " + loginhost); String baseurl = loginhost + "/services/oauth2/token"; // Send a post request to the OAuth URL. HttpPost oauthpost = new HttpPost(baseUrl); // The request body must contain these 5 values. 36

43 Code Examples Set Up Authentication with OAuth 2.0 List<BasicNameValuePair> parametersbody = new ArrayList<BasicNameValuePair>(); parametersbody.add(new BasicNameValuePair("grant_type", "password")); parametersbody.add(new BasicNameValuePair("username", username)); parametersbody.add(new BasicNameValuePair("password", password)); parametersbody.add(new BasicNameValuePair("client_id", clientid)); parametersbody.add(new BasicNameValuePair("client_secret", secret)); oauthpost.setentity(new UrlEncodedFormEntity(parametersBody, HTTP.UTF_8)); // Execute the request. System.out.println("POST " + baseurl + "...\n"); HttpResponse response = client.execute(oauthpost); int code = response.getstatusline().getstatuscode(); Map<String, String> oauthloginresponse = (Map<String, String>) JSON.parse(EntityUtils.toString(response.getEntity())); System.out.println("OAuth login response"); for (Map.Entry<String, String> entry : oauthloginresponse.entryset()) { System.out.println(String.format(" %s = %s", entry.getkey(), entry.getvalue())); System.out.println(""); // Get user info. String useridendpoint = oauthloginresponse.get("id"); String accesstoken = oauthloginresponse.get("access_token"); List<BasicNameValuePair> qslist = new ArrayList<BasicNameValuePair>(); qslist.add(new BasicNameValuePair("oauth_token", accesstoken)); String querystring = URLEncodedUtils.format(qsList, HTTP.UTF_8); HttpGet userinforequest = new HttpGet(userIdEndpoint + "?" + querystring); HttpResponse userinforesponse = client.execute(userinforequest); Map<String, Object> userinfo = (Map<String, Object>) JSON.parse(EntityUtils.toString(userInfoResponse.getEntity())); System.out.println("User info response"); for (Map.Entry<String, Object> entry : userinfo.entryset()) { System.out.println(String.format(" %s = %s", entry.getkey(), entry.getvalue())); System.out.println(""); // Use the user info in interesting ways. System.out.println("Username is " + userinfo.get("username")); System.out.println("User's is " + userinfo.get(" ")); Map<String, String> urls = (Map<String, String>)userInfo.get("urls"); System.out.println("REST API url is " + urls.get("rest").replace("{version", "41.0")); The output from this code resembles the following: Logging in as in environment POST OAuth login response 37

44 Code Examples Set Up Authentication with OAuth 2.0 id = issued_at = instance_url = access_token = 00D ehjI!ARYAQHc.0Mlmz.DCg3HRNF.SmsSn5njPkry2SM6pb6rjCOqfAODaUkv5CGksRSPRb.xb signature = 8M9VWBoaEk+Bs//yD+BfrUR/+5tkNLgXAIwal1PMwsY= User info response user_type = STANDARD status = {created_date= t16:44: , body=hello urls = {sobjects= feeds= users= query= enterprise= recent= feed_items= search= partner= rest= groups= metadata= profile= locale = en_us asserted_user = true id = nick_name = SampleNickname photos = {picture= thumbnail= display_name = Sample User first_name = Admin last_modified_date = T04:35: username = = organization_id = 00D ehjIEAQ last_name = User utcoffset = active = true user_id = THy8AAG language = en_us Username is User's is REST API url is 38

45 USING STREAMING API CHAPTER 4 In this chapter... PushTopic Queries Event Notification Rules Replay PushTopic Streaming Events Filtered Subscriptions Bulk Subscriptions Deactivating a Push Topic Working with PushTopics Each PushTopic record that you create corresponds to a channel in CometD. The channel name is the name of the PushTopic prefixed with /topic/, for example, /topic/mypushtopic. A Bayeux client can receive streamed events on this channel. The channel name is case-sensitive when you subscribe. Note: Updates performed by the Bulk API won t generate notifications, since such updates could flood a channel. As soon as a PushTopic record is created, the system starts evaluating record creates, updates, deletes, and undeletes for matches. Whenever there s a match, a new notification is generated. The server polls for new notifications for currently subscribed channels every second. This time may fluctuate depending on the overall server load. The PushTopic defines when notifications are generated in the channel. This is specified by configuring the following PushTopic fields: PushTopic Queries Events Notifications Note: To receive notifications, users must have read access on both the object in the PushTopic query and the PushTopic itself. 39

46 Working with PushTopics PushTopic Queries PushTopic Queries The PushTopic query is the basis of the PushTopic channel and defines which record create, update, delete, or undelete events generate a notification. This query must be a valid SOQL query. To ensure that notifications are sent in a timely manner, the following requirements apply to PushTopic queries. The query SELECT clause must include Id. For example: SELECT Id, Name FROM... Only one entity per query. The object must be valid for the specified API version. The fields that you specify in the PushTopic SELECT clause make up the body of the notification that is streamed on the PushTopic channel. For example, if your PushTopic query is SELECT Id, Name, Status c FROM InvoiceStatement c, then the ID, Name and Status c fields are included in any notifications sent on that channel. Following is an example of a notification message that might appear in that channel: { "channel": "/topic/invoicestatementupdates", "data": { "event": { "type": "updated", "createddate": " T15:59: ", "sobject": { "Name": "INV-0001", "Id": "a00d o6y8iaa", "Status c": "Open" If you change a PushTopic query, those changes take effect immediately on the server. A client receives events only if they match the new SOQL query. If you change a PushTopic Name, live subscriptions are not affected. New subscriptions must use the new channel name. Security and the PushTopic Query Subscribers receive notifications about records that were created, updated, deleted, or undeleted if they have: Field-level security access to the fields specified in the WHERE clause Read access on the object in the query Read access on the PushTopic Visibility of the new or modified record based on sharing rules If the subscriber doesn t have access to specific fields referenced in the query SELECT clause, then those fields aren t included in the notification. If the subscriber doesn t have access to all fields referenced in the query WHERE clause, then they will not receive the notification. 40

47 Working with PushTopics Supported PushTopic Queries For example, assume a user tries to subscribe to a PushTopic with the following Query value: SELECT Id, Name, SSN c FROM Employee c WHERE Bonus_Received c = true AND Bonus_Amount c > If the subscriber doesn't have access to Bonus_Received c or Bonus_Amount c, the subscription fails. If the subscriber doesn t have access to SSN c, then it won t be returned in the notification. If the subscriber has already successfully subscribed to the PushTopic, but the field-level security then changes so that the user no longer has access to one of the fields referenced in the WHERE clause, no streamed notifications are sent. Supported PushTopic Queries All custom objects are supported in PushTopic queries. The following subset of standard objects are supported in PushTopic queries: Account, Campaign, Case, Contact, Lead, Opportunity, Task. The following standard objects are supported in PushTopic queries through a pilot program: ContractLineItem, Entitlement, LiveChatTranscript, Quote, QuoteLineItem, ServiceContract. Important: Tasks that are created or updated using the following methods don t appear in task object topics in the streaming API. Lead conversion Entity merge Mass contacts/leads Also, the standard SOQL operators as well as most SOQL statements and expressions are supported. Some SOQL statements aren t supported. See Unsupported PushTopic Queries. The following are examples of supported SOQL statements. Custom object SELECT Id, MyCustomField c FROM MyCustomObject c Standard objects (may include custom fields) Account SELECT Id, Name FROM Account WHERE NumberOfEmployees > 1000 Campaign Case SELECT Id, Name FROM Campaign WHERE Status = 'Planned' SELECT Id, Subject FROM Case WHERE Status = 'Working' AND IsEscalated = TRUE Contact Lead SELECT Id, Name, FROM Contact; SELECT Id, Company FROM Lead WHERE Industry = 'Computer Services' 41

48 Working with PushTopics Compound Fields in PushTopic Queries Opportunity Task SELECT Id, Name, Amount FROM Opportunity WHERE CloseDate < SELECT Id, Subject, IsClosed, Status FROM Task WHERE isclosed = TRUE Important: To receive notifications on the IsClosed field, the subscriber must subscribe to the Status field referenced in the query. To receive notifications on the WhoCount and WhatCount fields, the subscriber must subscribe to the WhoId and WhatId fields. Subscriptions based only on the WhoCount or WhatCount fields aren t supported. Compound Fields in PushTopic Queries By default, the support of compound fields, such as Name or Address fields, depends on which fields are present in the PushTopic query. For Name compound fields, you must specify the Name field. For Address and Geolocation fields, you must specify the constituent fields. Note: If the PushTopic field NotifyForFields is set to All, compound fields are supported. In this case, it s not necessary to explicitly reference compound or constituent fields in the PushTopic query. The special behavior listed in the following sections applies only for the default NotifyForFields setting (Referenced) or when NotifyForFields is set to Select or Where. Name Compound Field To detect changes on the Name compound field, include the Name field in the SELECT or WHERE clause. The constituent fields, such as firstname and lastname, are optional, but the Name field is required. The returned notification message includes all constituent field values. If the Name field is omitted, changes can t be detected, even if the constituent fields are present. The following table shows supported and unsupported SELECT statements. These statements contain fields for the Name compound field on Contact or Lead. Fields SELECT Id, Name SELECT Id, Name, firstname, lastname SELECT Id, firstname, lastname Supported? Yes Yes No Address Compound Field To detect changes of Address compound fields, include the constituent fields in the SELECT or WHERE clause. The Address field, such as MailingAddress on Contact or ShippingAddress on Account, is optional, but the constituent fields are required. If the constituent fields are omitted, changes can t be detected, even if the Address field is present. The following table shows supported and unsupported SELECT statements. These statements contain MailingAddress fields of Contact. 42

49 Working with PushTopics Unsupported PushTopic Queries Fields SELECT Id, MailingAddress SELECT Id, MailingAddress, MailingCity, MailingStreet SELECT Id, MailingCity, MailingStreet Supported? No Yes Yes Geolocation Compound Field To detect changes of Geolocation compound fields, include the latitude and longitude constituent fields in the SELECT or WHERE clause. The Geolocation field is optional, but the constituent fields are required. If the constituent fields are omitted, changes can t be detected, even if the Geolocation field is present. The following table shows supported and unsupported SELECT statements. These statements contain a custom Geolocation field called location c and its constituent fields. Fields SELECT Id, location c SELECT Id, location c, location latitude s, location longitude s SELECT Id, location latitude s, location longitude s Supported? No Yes Yes Unsupported PushTopic Queries The following SOQL statements are not supported in PushTopic queries. Queries without an Id in the selected fields list Semi-joins and anti-joins Example query: SELECT Id, Name FROM Account WHERE Id IN (SELECT AccountId FROM Contact WHERE Title = 'CEO') Error message: INVALID_FIELD, semi/anti join sub-selects are not supported Aggregate queries (queries that use AVG, MAX, MIN, and SUM) Example query: SELECT Id, AVG(AnnualRevenue) FROM Account Error message: INVALID_FIELD, Aggregate queries are not supported COUNT Example query: SELECT Id, Industry, Count(Name) FROM Account Error message: INVALID_FIELD, Aggregate queries are not supported LIMIT Example query: SELECT Id, Name FROM Contact LIMIT 10 43

50 Working with PushTopics Event Notification Rules Error message: INVALID_FIELD, 'LIMIT' is not allowed Relationships aren t supported, but you can reference an ID: Example query: SELECT Id, Contact.Account.Name FROM Contact Error message: INVALID_FIELD, relationships are not supported Searching for values in Text Area fields. ORDER BY Example query: SELECT Id, Name FROM Account ORDER BY Name Error message: INVALID_FIELD, 'ORDER BY' clause is not allowed GROUP BY Example query: SELECT Id, AccountId FROM Contact GROUP BY AccountId Error message: INVALID_FIELD, 'Aggregate queries are not supported' Formula fields in WHERE clauses (formula fields are supported in SELECT clauses though.) NOT Example query: SELECT Id FROM Account WHERE NOT Name = 'Salesforce.com' Error message: INVALID_FIELD, 'NOT' is not supported To make this a valid query, change it to SELECT Id FROM Account WHERE Name!= 'Salesforce.com'. OFFSET Note: The NOT IN phrase is supported in PushTopic queries. Example query: SELECT Id, Name FROM Account WHERE City = 'New York' OFFSET 10 Error message: INVALID_FIELD, 'OFFSET' clause is not allowed TYPEOF Example query: SELECT TYPEOF Owner WHEN User THEN LastName ELSE Name END FROM Case Error message: INVALID_FIELD, 'TYPEOF' clause is not allowed Note: TYPEOF is currently available as a Developer Preview as part of the SOQL Polymorphism feature. For more information on enabling TYPEOF for your organization, contact Salesforce. Event Notification Rules Notifications are generated for record events based on how you configure your PushTopic. The Streaming API matching logic uses the NotifyForOperationCreate, NotifyForOperationUpdate, NotifyForOperationDelete, NotifyForOperationUndelete, and NotifyForFields fields in a PushTopic record to determine whether to generate a notification. Clients must connect using the cometd/29.0 (or later) Streaming API endpoint to receive delete and undelete event notifications. Events Events that may generate a notification are the creation, update, delete, or undelete of a record. The PushTopic NotifyForOperationCreate, NotifyForOperationUpdate, NotifyForOperationDelete, and 44

51 Working with PushTopics Notifications NotifyForOperationUndelete fields enable you to specify which events may generate a notification in that PushTopic channel. The fields are set as follows: Field NotifyForOperationCreate NotifyForOperationDelete NotifyForOperationUndelete NotifyForOperationUpdate Description true if a create operation should generate a notification, otherwise, false. true if a delete operation should generate a notification, otherwise, false. true if an undelete operation should generate a notification, otherwise, false. true if an update operation should generate a notification, otherwise, false. In API version 28.0 and earlier, you use the NotifyForOperations field to specify which events generate a notification, and can only specify create or update events. The NotifyForOperations values are: NotifyForOperations Value All (default) Create Update Extended Description Evaluate a record to possibly generate a notification whether the record has been created or updated. Evaluate a record to possibly generate a notification only if the record has been created. Evaluate a record to possibly generate a notification only if the record has been updated. A value of Extended means that neither create or update operations are set to generate events. This value is provided to allow clients written to API version 28.0 or earlier to work with Salesforce organizations configured to generate delete and undelete notifications. The event field values together with the NotifyForFields value provides flexibility when configuring when you want to generate notifications using Streaming API. Notifications After a record is created or updated (an event), the record is evaluated against the PushTopic query and a notification might be generated. A notification is the message sent to the channel as the result of an event. The notification is a JSON formatted message. The PushTopic field NotifyForFields specifies how the record is evaluated against the PushTopic query. The NotifyForFields values are: NotifyForFields Value All Referenced (default) Description Notifications are generated for all record field changes, provided the evaluated records match the criteria specified in the WHERE clause. Changes to fields referenced in the SELECT and WHERE clauses are evaluated. Notifications are generated for the evaluated records only if they match the criteria specified in the WHERE clause. 45

52 Working with PushTopics Notifications NotifyForFields Value Select Where Description Changes to fields referenced in the SELECT clause are evaluated. Notifications are generated for the evaluated records only if they match the criteria specified in the WHERE clause. Changes to fields referenced in the WHERE clause are evaluated. Notifications are generated for the evaluated records only if they match the criteria specified in the WHERE clause. The fields that you specify in the PushTopic query SELECT clause are contained in the notification message. NotifyForFields Set to All When you set the value of PushTopic.NotifyForFields to All, a change to any field value in the record causes the Streaming API matching logic to evaluate the record to determine if a notification should be generated. Changes to record field values cause this evaluation whether or not those fields are referenced in the PushTopic query SELECT clause or WHERE clause. Event Record is created Record is updated A notification is generated when The record field values match the values specified in the WHERE clause The record field values match the values specified in the WHERE clause Examples PushTopic Query SELECT Id, f1, f2, f3 FROM InvoiceStatement Result Generates a notification if any field values in the record have changed. SELECT Id, f1, f2 FROM InvoiceStatement WHERE f3 = 'abc' AND f4 LIKE 'xyz' Generates a notification if any field values in the record have changed and f3 and f4 match the values in the WHERE clause. SELECT Id FROM InvoiceStatement When Id is the only field in the SELECT clause, a notification is generated if any field values have changed. SELECT Id FROM InvoiceStatement WHERE f3 = 'abc' AND f4 LIKE 'xyz' SELECT Id FROM InvoiceStatement WHERE Id IN ('a07b kwz7iao', 'e10r keu9iao', 'v32b kwz7yep') SELECT Id, f1, f2 FROM InvoiceStatement WHERE Generates a notification if any field values in the record have changed and f3 and f4 match the values in the WHERE clause. Generates a notification if any field values in the record have changed and the record ID is contained in the WHERE clause IN list. Generates a notification if any field values in the record have changed and the record ID is contained in the WHERE clause IN list. 46

53 Working with PushTopics Notifications PushTopic Query Result Id IN ('a07b kwz7iao', 'e10r keu9iao', 'v32b kwz7yep') SELECT Id, f1, f2 FROM InvoiceStatement WHERE f3 = 'abc' AND f4 LIKE 'xyz' AND Id IN ('a07b kwz7iao', 'e10r keu9iao', 'v32b kwz7yep') Generates a notification if any field values in the record have changed, f3 and f4 match the WHERE clause, and the record ID is contained in the WHERE clause IN list. Warning: Use caution when setting NotifyForFields to All. When you use this value, then notifications are generated for all record field changes as long as the new field values match the values in the WHERE clause. Therefore, the number of generated notifications could potentially be large, and you may hit the daily quota of events limit. In addition, because every record change is evaluated and many notifications may be generated, this causes a heavier load on the system. NotifyForFields Set to Referenced When you set the value of PushTopic.NotifyForFields to Referenced, a change to any field value in the record as long as that field is referenced in the query SELECT clause or WHERE clause causes the Streaming API matching logic to evaluate the record to determine if a notification should be generated. If the PushTopic.NotifyForFields value is Referenced, then the PushTopic query must have a SELECT clause with at least one field other than ID or a WHERE clause with at least one field other than Id. Event Record is created Record is updated A notification is generated when The record field values match the values specified in the WHERE clause A change occurs in one or more record fields that are specified in the PushTopic query SELECT clause or A change occurs in one or more record fields that are specified in the PushTopic query WHERE clause and The record values of the fields specified in the WHERE clause all match the values in the PushTopic query WHERE clause Examples PushTopic Query SELECT Id, f1, f2, f3 FROM InvoiceStatement c Result Generates a notification if f1, f2, or f3 have changed. 47

54 Working with PushTopics Notifications PushTopic Query SELECT Id, f1, f2 FROM InvoiceStatement c WHERE f3 = 'abc' AND f4 LIKE 'xyz' SELECT Id FROM InvoiceStatement c WHERE f3 = 'abc' AND f4 LIKE 'xyz' SELECT Id, f1, f2 FROM InvoiceStatement c WHERE Id IN ('a07b kwz7iao', 'e10r keu9iao', 'v32b kwz7yep') SELECT Id, f1, f2 FROM InvoiceStatement c WHERE f3 = 'abc' AND f4 LIKE 'xyz' AND Id IN ('a07b kwz7iao', 'e10r keu9iao', 'v32b kwz7yep') Result Generates a notification if f1, f2, f3, or f4 have changed and f3 and f4 match the values in the WHERE clause. Generates a notification if f3 and f4 have changed and f3 and f4 match the values in the WHERE clause. Generates a notification if f1 or f2 have changed and the record ID is contained in the WHERE clause IN list. Generates a notification if f1, f2, f3, or f4 have changed, f3 and f4 match the values in the WHERE clause, and the ID is contained in the WHERE clause IN list. NotifyForFields Set to Select When you set the value of PushTopic.NotifyForFields to Select, a change to any field value in the record as long as that field is referenced in the query SELECT clause causes the Streaming API matching logic to evaluate the record to determine if a notification should be generated. If the PushTopic.NotifyForFields value is Select, then the PushTopic query must have a SELECT clause with at least one field other than ID. Event Record is created Record is updated A notification is generated when The record field values match the values specified in the WHERE clause A change occurs in one or more record fields that are specified in the PushTopic query SELECT clause and The record values of the fields specified in the WHERE clause all match the values in the PushTopic query WHERE clause Examples PushTopic Query SELECT Id, f1, f2, f3 FROM InvoiceStatement c Result Generates a notification if f1, f2, or f3 have changed. 48

55 Working with PushTopics Notifications PushTopic Query SELECT Id, f1, f2 FROM InvoiceStatement c WHERE f3 = 'abc' AND f4 LIKE 'xyz' SELECT Id, f1, f2 FROM InvoiceStatement c WHERE Id IN ('a07b kwz7iao', 'e10r keu9iao', 'v32b kwz7yep') SELECT Id, f1, f2 FROM InvoiceStatement c WHERE f3 = 'abc' AND f4 LIKE 'xyz' AND Id IN ('a07b kwz7iao', 'e10r keu9iao', 'v32b kwz7yep') Result Generates a notification if f1 or f2 have changed and f3 and f4 match the values in the WHERE clause. Generates a notification if f1 or f2 have changed and ID is contained in the WHERE clause IN list. Generates a notification if f1 or f2 have changed, f3 and f4 match the values in the WHERE clause, and the ID is contained in the WHERE clause IN list. NotifyForFields Set to Where When you set the value of PushTopic.NotifyForFields to Where, a change to any field value in the record as long as that field is referenced in the query WHERE clause causes the Streaming API matching logic to evaluate the record to determine if a notification should be generated. If the PushTopic.NotifyForFields value is Where, then the PushTopic query must have a WHERE clause with at least one field other than Id. Event Record is created Record is updated A notification is generated when The record field values match the values specified in the WHERE clause A change occurs in one or more record fields that are specified in the PushTopic query WHERE clause and The record values of the fields specified in the WHERE clause all match the values in the PushTopic query WHERE clause Examples PushTopic Query SELECT Id, f1, f2 FROM InvoiceStatement c WHERE f3 = 'abc' AND f4 LIKE 'xyz' SELECT Id FROM InvoiceStatement c WHERE f3 = 'abc' AND f4 LIKE 'xyz' Result Generates a notification if f3 or f4 have changed and the values match the values in the WHERE clause. Generates a notification if f3 or f4 have changed and the values match the values in the WHERE clause. 49

56 Working with PushTopics Notifications PushTopic Query SELECT Id, f1, f2 FROM InvoiceStatement c WHERE f3 = 'abc' AND f4 LIKE 'xyz' AND Id IN ('a07b kwz7iao', 'e10r keu9iao', 'v32b kwz7yep') Result Generates a notification if f3 or f4 have changed, f3 and f4 match the values in the WHERE clause, and the record ID is contained in the WHERE clause IN list. Notification Scenarios Following is a list of example scenarios and the field values you need in a PushTopic record to generate notifications. Scenario You want to receive all notifications of all record updates. You want to receive notifications of all record changes only when the Name or Amount fields change. For example, if you re maintaining a list view. You want to receive notification of all record changes made to a specific record. You want to receive notification only when the Name or Amount field changes for a specific record. For example, if the user is on a detail page and only those two fields are displayed. You want to receive notification for all invoice statement record changes for vendors in a particular state. You want to receive notification for all invoice statement record changes where the invoice amount is $1,000 or more. Configuration MyPushTopic.Query = SELECT Id, Name, Description c FROM InvoiceStatement MyPushTopic.NotifyForFields = All MyPushTopic.Query = SELECT Id, Name, Amount c FROM InvoiceStatement MyPushTopic.NotifyForFields = Referenced MyPushTopic.Query = SELECT Id, Name, Amount c FROM InvoiceStatement WHERE Id='a07B KWZ7IAO' MyPushTopic.NotifyForFields = All MyPushTopic.Query = SELECT Id, Name, Amount c FROM InvoiceStatement WHERE Id='a07B KWZ7IAO' MyPushTopic.NotifyForFields = Referenced MyPushTopic.Query = SELECT Id, Name, Amount c FROM InvoiceStatement WHERE BillingState c = 'NY' MyPushTopic.NotifyForFields = All MyPushTopic.Query = SELECT Id, Name FROM InvoiceStatement WHERE Amount > 999 MyPushTopic.NotifyForFields = Referenced 50

57 Working with PushTopics Replay PushTopic Streaming Events Replay PushTopic Streaming Events Salesforce stores PushTopic-based events for 24 hours and allows you to retrieve stored and new events. Subscribers can choose which events to receive by using replay options. For more information about durable events, see Message Durability. Code Samples GitHub: Durable PushTopic Streaming Demo GitHub: Streaming Replay Client Extensions Filtered Subscriptions Reduce the number of PushTopic event notifications by specifying record fields to filter on when you subscribe to a channel. Specify the filter criteria in an expression you append to the subscription URI, as follows. /topic/channelname?<expression> ChannelName is the channel, and <expression> is the expression containing one or more conditions. Join conditions with the & operator. Only the & operator is supported. Use this syntax for the <expression>.?fielda=valuea&fieldb=valueb&... Include each field used in a filter condition in the PushTopic query. The & operator acts like the logical OR operator, so record events are matched if any condition is true. Note: If you use an ID in filter criteria, use the 18-character ID format; 15-character IDs aren t supported. Example: This subscription returns event notifications for records whose industry is Energy or shipping city is San Francisco. /topic/mychannel?industry='energy'&shippingcity='san Francisco' The PushTopic query for this subscription includes the Industry and ShippingCity fields. Bulk Subscriptions You can subscribe to multiple topics at the same time. To do so, send a JSON array of subscribe messages instead of a single subscribe message. For example this code subscribes to three topics: [ { "channel": "/meta/subscribe", "clientid": "Un1q31d3nt1f13r", "subscription": "/topic/foo", { "channel": "/meta/subscribe", "clientid": "Un1q31d3nt1f13r", "subscription": "/topic/bar" 51

58 Working with PushTopics Deactivating a Push Topic, { "channel": "/meta/subscribe", "clientid": "Un1q31d3nt1f13r", "subscription": "/topic/baz" ] For more information, see the Bayeux Specification. Deactivating a Push Topic You can temporarily deactivate a PushTopic, rather than deleting it, by setting the isactive field to false. To deactivate a PushTopic by Id, execute the following Apex code: PushTopic pt = new PushTopic(Id='0IFD jOAA', IsActive = false); update(pt); 52

59 CHAPTER 5 In this chapter... Clients and Timeouts Clients and Cookies for Streaming API Supported CometD Versions HTTPS Recommended Debugging Streaming API Applications Monitoring Events Usage Notification Message Order Considerations for Multiple Notifications in the Same Transaction Streaming API Considerations Streaming API helps you create near real-time update notifications of your Salesforce data. This chapter covers some client and troubleshooting considerations to keep in mind when implementing Streaming API. 53

60 Streaming API Considerations Clients and Timeouts Clients and Timeouts Streaming API imposes two timeouts, as supported in the Bayeux protocol. Socket timeout: 110 seconds A client receives events (JSON-formatted HTTP responses) while it waits on a connection. If no events are generated and the client is still waiting, the connection times out after 110 seconds and the server closes the connection. Clients should reconnect before two minutes to avoid the connection timeout. Reconnect timeout: 40 seconds After receiving the events, a client needs to reconnect to receive the next set of events. If the reconnection doesn't happen within 40 seconds, the server expires the subscription and the connection is closed. If this happens, the client must start again and handshake, subscribe, and connect. Each Streaming API client logs into an instance and maintains a session. When the client handshakes, connects, or subscribes, the session timeout is restarted. A client session times out if the client doesn t reconnect to the server within 40 seconds after receiving a response (an event, subscribe result, and so on). Note that these timeouts apply to the Streaming API client session and not the Salesforce authentication session. If the client session times out, the authentication session remains active until the organization-specific timeout policy goes into effect. Note: In addition to timeouts, a client might disconnect from the channel due to network failures. For more information, see Short Network Failures and Long Network Failures or Server Failures in the CometD Reference Documentation. Clients and Cookies for Streaming API The client you create to work with the Streaming API must obey the standard cookie protocol with the server. The client must accept and send the appropriate cookies for the domain and URI path, for example Streaming API requirements on clients: The "Content-Type: application/json" header is required on all calls to the cometd servlet if the content of the post is JSON. A header containing the Salesforce session ID or OAuth token is required. For example, Authorization: Bearer sessionid. The client must accept and send back all appropriate cookies for the domain and URI path. Clients must obey the standard cookie protocol with the server. The subscribe response and other responses might contain the following fields. These fields aren't contained in the CometD specification. EventType contains either created or updated. CreatedDate contains the event's creation date. Supported CometD Versions Use CometD version or later in your clients to connect to Streaming API. Earlier versions aren t supported and could result in unexpected behavior. To prevent potential issues with old CometD versions in your clients, upgrade the CometD library to a supported version. For more information, see 54

61 Streaming API Considerations HTTPS Recommended HTTPS Recommended Streaming API follows the preference set by your administrator for your organization. By default this is HTTPS. To protect the security of your data, we recommend you use HTTPS. Debugging Streaming API Applications You must be able to see all of the requests and responses in order to debug Streaming API applications. Because Streaming API applications are stateful, you need to use a proxy tool to debug your application. Use a tool that can report the contents of all requests and results, such as Burp Proxy, Fiddler, or Firebug. The most common errors include: Browser and JavaScript issues Sending requests out of sequence Malformed requests that don't follow the Bayeux protocol Authorization issues Network or firewall issues with long-lived connections Using these tools, you can look at the requests, headers, body of the post, as well as the results. If you must contact us for help, be sure to copy and save these elements to assist in troubleshooting. The first step for any debugging process is to follow the instructions in the Quick Start Using Workbench, Example: Interactive Visualforce Page without Replay, or Example: Subscribe to and Replay Events Using a Java Client and verify that you can implement the samples provided. The next step is to use your debug tool to help isolate the symptoms and cause of any problems. 402 Error You may sometimes receive an error notification that contains 402::Unknown client and looks something like this: Thu Mar 29 06:08:08 PDT 2012 [CHANNEL:META_CONNECT]: {"id":"78","error":"402::unknown client","successful":false,"advice":{"interval":500,"reconnect":"handshake" This can be caused by various conditions including when your client connection times out. If you see this error, you should reconnect to the server with a handshake. For more information about client timeouts and Streaming API limits, see Clients and Timeouts and Streaming API Limits. Monitoring Events Usage The number of events that can be generated in a 24 hour period depends on your type of organization. For more information, see Streaming API Limits. You can monitor Streaming API events usage on the Company Information page. From Setup, enter Company Information in the Quick Find box, then select Company Information. If you refresh the Company Information page, the Streaming API Events value may fluctuate slightly. Regardless of these small fluctuations, your limits are being assessed accurately. 55

62 Streaming API Considerations Notification Message Order Notification Message Order Changes to data in your organization happen in a sequential manner. However, the order in which you receive event notification messages in Streaming API isn t guaranteed. On the client side, you can use createddate to order the notification messages returned in a channel. The value of createddate is a UTC date/time value that indicates when the event occurred. This code shows multiple messages, one generated by the creation of a record and one generated by the update of a record. { { "channel": "/topic/invoicestatementupdates", "clientid": "1g177wgjj14omtdo3rcl0hjhm4w", "data": { "event": { "type": "updated", "createddate": " T18:16: ", "sobject": { "Name": "INV-0002", "test_ds Status c": "Negotiating", "test_ds Description c": "Update to invoice statement #2", "Id": "a00d pvxciaa" "channel": "/topic/invoicestatementupdates", "clientid": "1g177wgjj14omtdo3rcl0hjhm4w", "data": { "event": { "type": "created", "createddate": " T18:15: ", "sobject": { "Name": "INV-0003", "test_ds Status c": "Open", "test_ds Description c": "New invoice statement #1", "Id": "a00d pvzdiaa" Considerations for Multiple Notifications in the Same Transaction Check out these knowledge articles to learn about the behavior of Streaming API when multiple notifications are delivered within the same transaction. Streaming API Notifications Are Sent in Reverse Order Within a Transaction Multiple Streaming API Notifications for the Same Record - Notifications Are Sent for Untracked Fields (API Version 36.0 and Earlier) Only Last Push Topic Notification is sent out of multiple notifications done in short time 56

63 GENERIC STREAMING CHAPTER 6 In this chapter... Replay Generic Streaming Events with Durable Generic Streaming Introducing Generic Streaming Generic streaming uses Streaming API to send notifications of general events that are not tied to Salesforce data changes. Use generic streaming when you want to send and receive notifications based on custom events that you specify. You can use generic streaming for any situation where you need to send custom notifications, such as: Broadcasting notifications to specific teams or to your entire organization Sending notifications for events that are external to Salesforce To use generic streaming, you need: A StreamingChannel that defines the channel, with a name that is case-sensitive One or more clients subscribed to the channel The Streaming Channel Push REST API resource that lets you monitor and invoke push events on the channel 57

64 Introducing Generic Streaming Replay Generic Streaming Events with Durable Generic Streaming Replay Generic Streaming Events with Durable Generic Streaming A client can receive generic streaming events after it subscribes to a channel and as long as the Salesforce session is active. Events sent before a client subscribes to a channel or after a subscribed client disconnects from the Salesforce session are missed. However, a client can fetch the missed events within the 24-hour retention window by using Durable Generic Streaming. For more information about durable events, see Message Durability. Code Sample See theses code samples about replaying generic streaming events. Generic Streaming Quick Start Example: Subscribe to and Replay Events Using a Visualforce Page 58

65 CHAPTER 7 Generic Streaming Quick Start This quick start shows you how to get started with generic streaming in Streaming API. This quick start takes you step-by-step through the process of using Streaming API to receive a notification when an event is pushed via REST and lets you specify replay options. IN THIS SECTION: Create a Streaming Channel Create a new StreamingChannel object by using the Salesforce UI. Run a Java Client with Username and Password Login Run a Java client that uses EMP Connector to subscribe to the channel with username and password authentication. Run a Java Client with OAuth Bearer Token Login Run a Java client that uses EMP Connector to subscribe to the channel with OAuth authentication. Generate Events Using REST Use the Streaming Channel Push REST API resource to generate event notifications to channel subscribers. Create a Streaming Channel Create a new StreamingChannel object by using the Salesforce UI. You must have the proper Streaming API permissions enabled in your organization. 1. Log in to your Developer Edition organization. 2. If you re using Salesforce Classic, under All Tabs (+), select Streaming Channels. If you re using Lightning Experience, from the App Launcher, select All Items, and then click Streaming Channels. 3. On the Streaming Channels page, click New to create a streaming channel. 4. Enter /u/notifications/exampleuserchannel in Streaming Channel Name, and an optional description. Your new Streaming Channel page should look something like this: 59

Streaming API Developer Guide

Streaming API Developer Guide Streaming API Developer Guide Version 43.0, Summer 18 @salesforcedocs Last updated: August 2, 2018 Copyright 2000 2018 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of

More information

Force.com Streaming API Developer Guide

Force.com Streaming API Developer Guide Force.com Streaming API Developer Guide Version 40.0, Summer 17 @salesforcedocs Last updated: August 9, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Streaming API Developer Guide

Streaming API Developer Guide Streaming API Developer Guide Version 44.0, Winter 19 @salesforcedocs Last updated: October 22, 2018 Copyright 2000 2018 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of

More information

Force.com Streaming API Developer's Guide

Force.com Streaming API Developer's Guide Force.com Streaming API Developer's Guide Version 34.0, Summer 15 @salesforcedocs Last updated: June 30, 2015 Copyright 2000 2015 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Custom Metadata Types Implementation Guide

Custom Metadata Types Implementation Guide Custom Metadata Types Implementation Guide Salesforce, Winter 17 @salesforcedocs Last updated: December 9, 2016 Copyright 2000 2016 salesforce.com, inc. All rights reserved. Salesforce is a registered

More information

Salesforce CRM Content Implementation Guide

Salesforce CRM Content Implementation Guide Salesforce CRM Content Implementation Guide Salesforce, Winter 18 @salesforcedocs Last updated: October 13, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered

More information

SALESFORCE DEVELOPER LIMITS AND ALLOCATIONS QUICK REFERENCE

SALESFORCE DEVELOPER LIMITS AND ALLOCATIONS QUICK REFERENCE SALESFORCE DEVELOPER LIMITS AND ALLOCATIONS QUICK REFERENCE Summary Find the most critical limits for developing Lightning Platform applications. About This Quick Reference This quick reference provides

More information

Package and Distribute Your Apps

Package and Distribute Your Apps Package and Distribute Your Apps Salesforce, Summer 18 @salesforcedocs Last updated: July 30, 2018 Copyright 2000 2018 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of

More information

Custom Metadata Types Implementation Guide

Custom Metadata Types Implementation Guide Custom Metadata Types Implementation Guide Salesforce, Spring 18 @salesforcedocs Last updated: January 16, 2018 Copyright 2000 2018 salesforce.com, inc. All rights reserved. Salesforce is a registered

More information

Sync to a Secondary Salesforce Organization

Sync to a Secondary Salesforce Organization Sync to a Secondary Salesforce Organization Salesforce, Summer 17 @salesforcedocs Last updated: August 9, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

SALESFORCE DEVELOPER LIMITS AND ALLOCATIONS QUICK REFERENCE

SALESFORCE DEVELOPER LIMITS AND ALLOCATIONS QUICK REFERENCE SALESFORCE DEVELOPER LIMITS AND ALLOCATIONS QUICK REFERENCE Summary Find the most critical limits for developing Lightning Platform applications. About This Quick Reference This quick reference provides

More information

MIGRATING FROM PORTALS TO COMMUNITIES

MIGRATING FROM PORTALS TO COMMUNITIES MIGRATING FROM PORTALS TO COMMUNITIES Introduction Have a partner portal or customer portal in your org? You can set up a community as well, to take advantage of the great new features that Salesforce

More information

Convert Your JavaScript Buttons for Lightning Experience

Convert Your JavaScript Buttons for Lightning Experience Convert Your JavaScript Buttons for Lightning Experience Version 1, 1 @salesforcedocs Last updated: January 8, 2019 Copyright 2000 2019 salesforce.com, inc. All rights reserved. Salesforce is a registered

More information

Chatter Answers Implementation Guide

Chatter Answers Implementation Guide Chatter Answers Implementation Guide Salesforce, Summer 18 @salesforcedocs Last updated: July 26, 2018 Copyright 2000 2018 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Chatter Answers Implementation Guide

Chatter Answers Implementation Guide Chatter Answers Implementation Guide Salesforce, Spring 16 @salesforcedocs Last updated: April 27, 2016 Copyright 2000 2016 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Package and Distribute Your Apps

Package and Distribute Your Apps Package and Distribute Your Apps Salesforce, Summer 17 @salesforcedocs Last updated: August 9, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of

More information

Custom Metadata Types Implementation Guide

Custom Metadata Types Implementation Guide Custom Metadata Types Implementation Guide Salesforce, Summer 18 @salesforcedocs Last updated: July 3, 2018 Copyright 2000 2018 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

SALESFORCE DEVELOPER LIMITS AND ALLOCATIONS QUICK REFERENCE

SALESFORCE DEVELOPER LIMITS AND ALLOCATIONS QUICK REFERENCE SALESFORCE DEVELOPER LIMITS AND ALLOCATIONS QUICK REFERENCE Summary Find the most critical limits for developing Lightning Platform applications. About This Quick Reference This quick reference provides

More information

Salesforce CRM Content Implementation Guide

Salesforce CRM Content Implementation Guide Salesforce CRM Content Implementation Guide Salesforce, Summer 16 @salesforcedocs Last updated: June 7, 2016 Copyright 2000 2016 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Salesforce IoT REST API Getting Started Guide

Salesforce IoT REST API Getting Started Guide Salesforce IoT REST API Getting Started Guide Version 42.0, Spring 18 @salesforcedocs Last updated: March 9, 2018 Copyright 2000 2018 salesforce.com, inc. All rights reserved. Salesforce is a registered

More information

Platform Events Developer Guide

Platform Events Developer Guide Platform Events Developer Guide Version 44.0, Winter 19 @salesforcedocs Last updated: October 1, 2018 Copyright 2000 2018 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Getting Started with the Aloha Community Template for Salesforce Identity

Getting Started with the Aloha Community Template for Salesforce Identity Getting Started with the Aloha Community Template for Salesforce Identity Salesforce, Winter 18 @salesforcedocs Last updated: November 30, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved.

More information

Comet and WebSocket Web Applications How to Scale Server-Side Event-Driven Scenarios

Comet and WebSocket Web Applications How to Scale Server-Side Event-Driven Scenarios Comet and WebSocket Web Applications How to Scale Server-Side Event-Driven Scenarios Simone Bordet sbordet@intalio.com 1 Agenda What are Comet web applications? Impacts of Comet web applications WebSocket

More information

Platform Events Developer Guide

Platform Events Developer Guide Platform Events Developer Guide Version 41.0, Winter 18 @salesforcedocs Last updated: December 8, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

License Management and Support Guide

License Management and Support Guide License Management and Support Guide Salesforce, Summer 18 @salesforcedocs Last updated: June 20, 2018 Copyright 2000 2018 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Deploy Enhancements from Sandboxes

Deploy Enhancements from Sandboxes Deploy Enhancements from Sandboxes Salesforce, Spring 18 @salesforcedocs Last updated: April 13, 2018 Copyright 2000 2018 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Enhance Your Sales Cloud Implementation

Enhance Your Sales Cloud Implementation Enhance Your Sales Cloud Implementation Salesforce, Winter 18 @salesforcedocs Last updated: November 2, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Identity Implementation Guide

Identity Implementation Guide Identity Implementation Guide Version 36.0, Spring 16 @salesforcedocs Last updated: March 3, 2016 Copyright 2000 2016 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of salesforce.com,

More information

Set Up and Manage Salesforce Communities

Set Up and Manage Salesforce Communities Set Up and Manage Salesforce Communities Salesforce, Spring 16 @salesforcedocs Last updated: April 28, 2016 Copyright 2000 2016 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Snap-Ins Chat. Salesforce, Winter

Snap-Ins Chat. Salesforce, Winter Salesforce, Winter 18 @salesforcedocs Last updated: December 1, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of salesforce.com, inc., as are other

More information

Enhance Salesforce with Code

Enhance Salesforce with Code Salesforce, Spring 17 @salesforcedocs Last updated: April 3, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of salesforce.com, inc., as are other

More information

Database.com Streaming API Developer's Guide

Database.com Streaming API Developer's Guide Version 25.0: Summer 12 Database.com Streaming API Developer's Guide Last updated: September 1 2012 Copyright 2000 2012 salesforce.com, inc. All rights reserved. Salesforce.com is a registered trademark

More information

Manage Duplicate Records in Salesforce PREVIEW

Manage Duplicate Records in Salesforce PREVIEW Manage Duplicate Records in Salesforce Salesforce, Winter 18 PREVIEW Note: This release is in preview. Features described in this document don t become generally available until the latest general availability

More information

Salesforce Developer Limits Quick Reference

Salesforce Developer Limits Quick Reference Salesforce Developer Limits Quick Reference Version 41.0, Winter 18 @salesforcedocs Last updated: November 30, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered

More information

Salesforce Lead Management Implementation Guide

Salesforce Lead Management Implementation Guide Salesforce Lead Management Implementation Guide Salesforce, Winter 16 @salesforcedocs Last updated: October 1, 2015 Copyright 2000 2015 salesforce.com, inc. All rights reserved. Salesforce is a registered

More information

Database.com Streaming API Developer's Guide

Database.com Streaming API Developer's Guide Version 30.0: Spring 14 Database.com Streaming API Developer's Guide Last updated: May 5, 2014 Copyright 2000 2014 salesforce.com, inc. All rights reserved. Salesforce.com is a registered trademark of

More information

USER MANUAL. SalesPort Salesforce Customer Portal for WordPress (Lightning Mode) TABLE OF CONTENTS. Version: 3.1.0

USER MANUAL. SalesPort Salesforce Customer Portal for WordPress (Lightning Mode) TABLE OF CONTENTS. Version: 3.1.0 USER MANUAL TABLE OF CONTENTS Introduction...1 Benefits of Customer Portal...1 Prerequisites...1 Installation...2 Salesforce App Installation... 2 Salesforce Lightning... 2 WordPress Manual Plug-in installation...

More information

Identity Implementation Guide

Identity Implementation Guide Identity Implementation Guide Version 39.0, Spring 17 @salesforcedocs Last updated: March 14, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of

More information

Salesforce Classic Mobile Implementation Guide

Salesforce Classic Mobile Implementation Guide Salesforce Classic Mobile Implementation Guide Version 40.0, Summer @salesforcedocs Last updated: August 9, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered

More information

Utility Bar API Implementation Guide

Utility Bar API Implementation Guide Utility Bar API Implementation Guide Salesforce, Winter 18 @salesforcedocs Last updated: November 2, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Identity Implementation Guide

Identity Implementation Guide Identity Implementation Guide Version 36.0, Spring 16 @salesforcedocs Last updated: April 28, 2016 Copyright 2000 2016 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of

More information

Set Up and Maintain Collaboration Tools

Set Up and Maintain Collaboration Tools Set Up and Maintain Collaboration Tools Salesforce, Winter 18 @salesforcedocs Last updated: December 6, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Salesforce Classic Mobile Implementation Guide

Salesforce Classic Mobile Implementation Guide Salesforce Classic Mobile Implementation Guide Version 42.0, Spring 18 @salesforcedocs Last updated: April 6, 2018 Copyright 2000 2018 salesforce.com, inc. All rights reserved. Salesforce is a registered

More information

Salesforce Mobile App URL Schemes

Salesforce Mobile App URL Schemes Salesforce Mobile App URL Schemes Version 2, 2 @salesforcedocs Last updated: November 2, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of salesforce.com,

More information

Case Management Implementation Guide

Case Management Implementation Guide Case Management Implementation Guide Salesforce, Winter 18 @salesforcedocs Last updated: November 30, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Salesforce Limits Quick Reference Guide

Salesforce Limits Quick Reference Guide Salesforce Limits Quick Reference Guide Version 35.0, Winter 16 @salesforcedocs Last updated: December 3, 2015 Copyright 2000 2015 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Visual Workflow Implementation Guide

Visual Workflow Implementation Guide Version 30.0: Spring 14 Visual Workflow Implementation Guide Note: Any unreleased services or features referenced in this or other press releases or public statements are not currently available and may

More information

Identity Implementation Guide

Identity Implementation Guide Identity Implementation Guide Version 41.0, Winter 18 @salesforcedocs Last updated: November 22, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Live Agent Developer Guide

Live Agent Developer Guide Live Agent Developer Guide Version 41.0, Winter 18 @salesforcedocs Last updated: November 30, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of

More information

Deploy Enhancements from Sandboxes

Deploy Enhancements from Sandboxes Deploy Enhancements from Sandboxes Salesforce, Spring 17 @salesforcedocs Last updated: March 10, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Identity Implementation Guide

Identity Implementation Guide Identity Implementation Guide Version 42.0, Spring 18 @salesforcedocs Last updated: February 13, 2018 Copyright 2000 2018 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Salesforce External Identity Implementation Guide

Salesforce External Identity Implementation Guide Salesforce External Identity Implementation Guide Salesforce, Winter 18 @salesforcedocs Last updated: December 20, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered

More information

Salesforce Lead Management Implementation Guide

Salesforce Lead Management Implementation Guide Salesforce Lead Management Implementation Guide Salesforce, Winter 18 @salesforcedocs Last updated: November 7, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered

More information

Identity Implementation Guide

Identity Implementation Guide Identity Implementation Guide Version 39.0, Spring 17 @salesforcedocs Last updated: January 11, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of

More information

Omni-Channel for Administrators

Omni-Channel for Administrators Omni-Channel for Administrators Salesforce, Spring 18 @salesforcedocs Last updated: February 1, 2018 Copyright 2000 2018 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of

More information

Salesforce Limits. Salesforce, Spring

Salesforce Limits. Salesforce, Spring Salesforce Limits Salesforce, Spring 16 @salesforcedocs Last updated: April 28, 2016 Copyright 2000 2016 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of salesforce.com,

More information

RSA NetWitness Logs. Salesforce. Event Source Log Configuration Guide. Last Modified: Wednesday, February 14, 2018

RSA NetWitness Logs. Salesforce. Event Source Log Configuration Guide. Last Modified: Wednesday, February 14, 2018 RSA NetWitness Logs Event Source Log Configuration Guide Salesforce Last Modified: Wednesday, February 14, 2018 Event Source Product Information: Vendor: Salesforce Event Source: CRM Versions: API v1.0

More information

SALESFORCE CERTIFIED PLATFORM DEVELOPER I

SALESFORCE CERTIFIED PLATFORM DEVELOPER I Certification Exam Guide SALESFORCE CERTIFIED PLATFORM DEVELOPER I Winter 19 2018 Salesforce.com, inc. All rights reserved. S ALESFORCE CERTIFIED PLATFORM DEVELOPER I CONTENTS About the Salesforce Certified

More information

Salesforce Classic Implementation Guide

Salesforce Classic Implementation Guide Salesforce Classic Implementation Guide Version 36.0, Spring 16 @salesforcedocs Last updated: April 27, 2016 Copyright 2000 2016 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Salesforce Console Implementation Guide

Salesforce Console Implementation Guide Salesforce Console Implementation Guide Salesforce, Summer 16 @salesforcedocs Last updated: August 12, 2016 Copyright 2000 2016 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Salesforce ldeas Implementation Guide

Salesforce ldeas Implementation Guide Salesforce ldeas Implementation Guide Salesforce, Winter 18 @salesforcedocs Last updated: November 30, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Snap-Ins Chat. Salesforce, Summer

Snap-Ins Chat. Salesforce, Summer Snap-Ins Chat Salesforce, Summer 17 @salesforcedocs Last updated: August 17, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of salesforce.com, inc.,

More information

Salesforce App Help. Salesforce, Winter

Salesforce App Help. Salesforce, Winter Salesforce App Help Salesforce, Winter 18 @salesforcedocs Last updated: November 22, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of salesforce.com,

More information

Deploy Enhancements from Sandboxes

Deploy Enhancements from Sandboxes Deploy Enhancements from Sandboxes Salesforce, Summer 16 @salesforcedocs Last updated: August 25, 2016 Copyright 2000 2016 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Salesforce Limits. Salesforce, Winter

Salesforce Limits. Salesforce, Winter Salesforce Limits Salesforce, Winter 18 @salesforcedocs Last updated: December 6, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of salesforce.com,

More information

Financial Services Cloud Quick Start

Financial Services Cloud Quick Start Financial Services Cloud Quick Start Salesforce, Spring 17 @salesforcedocs Last updated: April 11, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Salesforce Classic Mobile Guide for iphone

Salesforce Classic Mobile Guide for iphone Salesforce Classic Mobile Guide for iphone Version 41.0, Winter 18 @salesforcedocs Last updated: November 30, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered

More information

Opaali Portal Quick guide

Opaali Portal Quick guide Opaali Portal Quick guide Company information Telia Finland Oyj Teollisuuskatu 15, 00510 HELSINKI, FI Registered office: Helsinki Business ID 1475607-9, VAT No. FI14756079 1 (40) Page 2 (40) Copyright

More information

Change Data Capture Developer Guide

Change Data Capture Developer Guide Change Data Capture Developer Guide Version 44.0, Winter 19 @salesforcedocs Last updated: October 8, 2018 Copyright 2000 2018 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Lightning Knowledge Guide

Lightning Knowledge Guide Lightning Knowledge Guide Salesforce, Spring 18 @salesforcedocs Last updated: April 13, 2018 Copyright 2000 2018 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of salesforce.com,

More information

PREVIEW. Salesforce Limits. Salesforce, Winter

PREVIEW. Salesforce Limits. Salesforce, Winter Salesforce Limits Salesforce, Winter 18 PREVIEW Note: This release is in preview. Features described in this document don t become generally available until the latest general availability date that Salesforce

More information

NIELSEN API PORTAL USER REGISTRATION GUIDE

NIELSEN API PORTAL USER REGISTRATION GUIDE NIELSEN API PORTAL USER REGISTRATION GUIDE 1 INTRODUCTION In order to access the Nielsen API Portal services, there are three steps that need to be followed sequentially by the user: 1. User Registration

More information

Salesforce.com Winter 18 Release

Salesforce.com Winter 18 Release Salesforce.com Winter 18 Release October 2017 Copyright 2017 Veeva Systems Inc., all rights reserved veeva.com 1 Table of Contents SFDC Release Schedule and Deck Intentions Summary of Enhancements and

More information

Salesforce Classic Mobile User Guide for Android

Salesforce Classic Mobile User Guide for Android Salesforce Classic Mobile User Guide for Android Version 41.0, Winter 18 @salesforcedocs Last updated: November 21, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered

More information

Integration Workbook

Integration Workbook Integration Workbook: Spring '13 Integration Workbook Last updated: March 8, 2013 Copyright 2000 2013 salesforce.com, inc. All rights reserved. Salesforce.com is a registered trademark of salesforce.com,

More information

Salesforce.com Summer '10 Release Notes

Salesforce.com Summer '10 Release Notes Salesforce.com: Summer '10 Salesforce.com Summer '10 Release Notes Last updated: July 20, 2010 Copyright 2000-2010 salesforce.com, inc. All rights reserved. Salesforce.com is a registered trademark of

More information

Add Authentication to the Public Store Front

Add Authentication to the Public Store Front Salesforce.com: Winter '10 Last updated: November 24, 2009 Copyright 2000-2009 salesforce.com, inc. All rights reserved. Salesforce.com is a registered trademark of salesforce.com, inc., as are other names

More information

Salesforce Files Connect Implementation Guide

Salesforce Files Connect Implementation Guide Salesforce Files Connect Implementation Guide Salesforce, Summer 18 @salesforcedocs Last updated: May 30, 2018 Copyright 2000 2018 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Volunteers for Salesforce Installation & Configuration Guide Version 3.79

Volunteers for Salesforce Installation & Configuration Guide Version 3.79 Volunteers for Salesforce Installation & Configuration Guide Version 3.79 January 1, 2016 Djhconsulting.com 1 CONTENTS 1. Overview... 4 2. Installation Instructions... 4 2.1 Requirements Before Upgrading...

More information

TRAINING & CERTIFICATION. Salesforce.com Certified Force.com Advanced Developer Study Guide

TRAINING & CERTIFICATION. Salesforce.com Certified Force.com Advanced Developer Study Guide Salesforce.com Certified Force.com Advanced Developer Study Guide Contents About the Force.com Certification Program... 1 Section 1. Purpose of this Study Guide... 2 Section 2. Audience Description: Salesforce.com

More information

Salesforce Enterprise Edition Upgrade Guide

Salesforce Enterprise Edition Upgrade Guide Salesforce Enterprise Edition Upgrade Guide Salesforce, Spring 16 @salesforcedocs Last updated: February 11, 2016 Copyright 2000 2016 salesforce.com, inc. All rights reserved. Salesforce is a registered

More information

Force.com Sites Implementation Guide

Force.com Sites Implementation Guide Force.com Sites Implementation Guide Salesforce, Spring 18 @salesforcedocs Last updated: February 23, 2018 Copyright 2000 2018 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Manage Duplicate Records in Salesforce

Manage Duplicate Records in Salesforce Manage Duplicate Records in Salesforce Salesforce, Summer 18 @salesforcedocs Last updated: June 20, 2018 Copyright 2000 2018 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

ServiceMax Suite of Applications List of Fixed/Known Defects

ServiceMax Suite of Applications List of Fixed/Known Defects of Applications List of Fixed/Known Defects Copyright 2016 ServiceMax, Inc. All Rights Reserved. Designated trademarks and brands are the property of their respective owners. Fixed Issues For : 00054694

More information

Salesforce Classic Guide for iphone

Salesforce Classic Guide for iphone Salesforce Classic Guide for iphone Version 35.0, Winter 16 @salesforcedocs Last updated: October 27, 2015 Copyright 2000 2015 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Set Up and Configure Salesforce Advisor Link

Set Up and Configure Salesforce Advisor Link Set Up and Configure Salesforce Advisor Link Examples and illustrations throughout this document are for illustrative purposes only and not to be considered guidance on proper or required configurations.

More information

Mobile Android Configuration Guide

Mobile Android Configuration Guide Mobile Android Configuration Guide Version 21 SP-WX-MBLAND-CG-201801--R021.00 Sage 2018. All rights reserved. This document contains information proprietary to Sage and may not be reproduced, disclosed,

More information

Create and Manage Partner Portals

Create and Manage Partner Portals Create and Manage Partner Portals Salesforce, Summer 18 @salesforcedocs Last updated: June 20, 2018 Copyright 2000 2018 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of

More information

Set Up and Maintain Sales Tools

Set Up and Maintain Sales Tools Set Up and Maintain Sales Tools Salesforce, Spring 16 @salesforcedocs Last updated: February 18, 2016 Copyright 2000 2016 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Force.com Sites Implementation Guide

Force.com Sites Implementation Guide Force.com Sites Implementation Guide Salesforce, Winter 18 @salesforcedocs Last updated: November 30, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark

More information

Salesforce External Identity Implementation Guide

Salesforce External Identity Implementation Guide Salesforce External Identity Implementation Guide Salesforce, Summer 17 @salesforcedocs Last updated: September 28, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered

More information

Mobile ios Configuration Guide

Mobile ios Configuration Guide Mobile ios Configuration Guide Version 21 SP-WX-MBLIOS-CG-201801--R021.00 Sage 2018. All rights reserved. This document contains information proprietary to Sage and may not be reproduced, disclosed, or

More information

Omni-Channel for Administrators

Omni-Channel for Administrators Omni-Channel for Administrators Salesforce, Winter 18 @salesforcedocs Last updated: November 2, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of

More information

Live Agent for Support Agents

Live Agent for Support Agents Live Agent for Support Agents Salesforce, Winter 18 @salesforcedocs Last updated: November 30, 2017 Copyright 2000 2017 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of

More information

Document revision 1.0

Document revision 1.0 Document revision 1.0 Contents Installing the Application... 3 Basic Setup... 4 Lightning New/Edit Page Configuration... 6 Lightning App Page Configuration... 8 Standardization Options... 12 Enabling and

More information

SALESFORCE CERTIFIED PLATFORM DEVELOPER I

SALESFORCE CERTIFIED PLATFORM DEVELOPER I Certification Exam Guide SALESFORCE CERTIFIED PLATFORM DEVELOPER I Winter 18 2017 Salesforce.com, inc. All rights reserved. S ALESFORCE CERTIFIED PLATFORM DEVELOPER I CONTENTS About the Salesforce Certified

More information

Omni-Channel for Administrators

Omni-Channel for Administrators Omni-Channel for Administrators Salesforce, Summer 18 @salesforcedocs Last updated: August 16, 2018 Copyright 2000 2018 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of

More information

Development Lifecycle Guide

Development Lifecycle Guide Development Lifecycle Guide Enterprise Development on the Force.com Platform Version 41.0, Winter 18 @salesforcedocs Last updated: November 30, 2017 Copyright 2000 2017 salesforce.com, inc. All rights

More information

Visual Workflow Guide

Visual Workflow Guide Visual Workflow Guide Version 35.0, Winter 16 @salesforcedocs Last updated: December 17, 2015 Copyright 2000 2015 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of salesforce.com,

More information

Adobe Document Cloud esign Services. for Salesforce Version 17 Installation and Customization Guide

Adobe Document Cloud esign Services. for Salesforce Version 17 Installation and Customization Guide Adobe Document Cloud esign Services for Salesforce Version 17 Installation and Customization Guide 2015 Adobe Systems Incorporated. All rights reserved. Last Updated: August 28, 2015 Table of Contents

More information