Newer Version Available

This content describes an older version of this product. View Latest

(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.

Prerequisites

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 in Salesforce Help.

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.

    Note

    The sample fetches the earliest saved events within the past 24 hours. 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.
    • –2—Get all new events sent after subscription and all past events within the past 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.

    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.

    Note