Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

(Optional) Step 5: Use the Connector with OAuth Bearer Token Login

You can use the connector with OAuth authentication as an alternative to username and password authentication. This step is optional and requires an OAuth token.
Obtain an OAuth bearer access token for your Salesforce user. You supply this access token in the connector example.

See Set Up Authorization with OAuth 2.0. Also see Authorize Apps with OAuth.

Let’s run an example that uses OAuth bearer token login.
  1. In the /src/main/java/com/salesforce/emp/connector/example folder, open the BearerTokenExample.java Java source file.
  2. Run the BearerTokenExample class, and provide the following argument values.
    Argument Value
    url URL of the Salesforce instance of the logged-in user
    token The access token returned by the OAuth authentication flow
    channel The channel name for the PushTopic: /topic/InvoiceStatementUpdates

    This quick start is based on a PushTopic event. Alternatively, you can use EMP Connector to listen to any event type. The following lists channel name formats for a sample of streaming events available in the Lightning Platform.

    Platform event

    For a custom platform event—/event/EventName__e

    For a standard platform event—/event/EventName

    For a custom channel—/event/ChannelName__chn

    Change Data Capture event

    For all change events—/data/ChangeEvents

    For a specific standard object—/data/ObjectNameChangeEvent

    For a specific custom object—/data/CustomObjectName__ChangeEvent

    For a custom channel—/data/ChannelName__chn

    PushTopic event

    /topic/PushTopicName

    Generic event

    /u/notifications/GenericStreamingChannel

    Optionally, to receive different events, you can include a replay ID as the last argument. Valid values are:
    • –1 — Get all new events sent after subscription. This option is the default.
    • –2 — Get all new events sent after subscription and all past events within the retention window. Use -2 sparingly. If a large volume of event messages is stored, retrieving all event messages can slow performance.
    • 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.
    1Subscribed: Subscription [/topic/InvoiceStatementUpdates:-1]
    2Received:
    3{event={createdDate=2016-12-12T22:31:48.035Z, replayId=1, type=created}, sobject={Status__c=Open, Id=a070P00000pn0hyQAA, Name=INV-0001, Description__c=blah}}
    4Received:
    5{event={createdDate=2016-12-12T22:32:06.440Z, replayId=2, type=updated}, sobject={Status__c=Negotiating, Id=a070P00000pn0hyQAA, Name=INV-0001, Description__c=blah}}
    6Received:
    7{event={createdDate=2016-12-12T22:32:57.404Z, replayId=3, type=created}, sobject={Status__c=Open, Id=a070P00000pn0lfQAA, Name=INV-0002, Description__c=Laptops and accessories.}}

    If you’re listening to another event type, the output would look a bit different. Some events require that you publish the notification instead of Salesforce, such as with platform events.