Newer Version Available

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

Subscribe to a Standard Platform Event

Use EMP Connector to subscribe to the LoginEventStream standard platform event. This event tracks user logins in real time and is part of Real-time Event Monitoring.
  1. In Setup, enable streaming for the LoginEventStream event on the Event Manager page.

    LoginEventStream is part of Real-Time Event Monitoring. To enable streaming for this event in Event Manager and subscribe to the event, you must have the Shield Event Monitoring add-on and the View Real-Time Event Monitoring Data permission enabled. For more information, see Real Time Event Monitoring in Salesforce Help.

    Note

  2. In Eclipse, run the LoginExample class and provide arguments.
    1. In Package Explorer, navigate to the LoginExample.java file. Right-click the file, and select Run As | Run Configurations.
    2. On the Arguments tab, add values for the following arguments, separated by a space.
      Argument Value
      username Your Salesforce username
      password Your Salesforce password. Append a security token to your password if you haven't set up a range of trusted IP addresses. For more information, see Reset Your Security Token and Set Trusted IP Ranges for Your Organization in Salesforce Help.
      channel The channel name for the event. For the LoginEventStream standard event, provide /event/LoginEventStream.

      To perform this quick start with another standard event, pass in a channel name in the following format: /event/Event_Name

    3. Click Run.

    The sample is now subscribed to the event channel and is listening to event notifications. As soon as an event notification is generated and received, the tool prints it to the console.

    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 value: Get all events that occurred after the event with the specified replay ID.
  3. To generate an event message for a standard platform event, perform the action that fires the event. For LoginEventStream, log in to Salesforce.
    1. In a browser window, navigate to your org's login URL. For production orgs, it's in the format https://MyDomainName.my.salesforce.com.
    2. Enter your Salesforce username and password (or the credentials of another user in your org), and click Log In.
    3. After you log in, EMP Connector receives an event notification for the login action. The event message is printed in the console. The output looks similar to the following.
      1Subscribed: Subscription [/event/LoginEventStream:-1]
      2Received:
      3{  
      4   "schema":"3J6UjLfL6cDEeBI84DSyTA",
      5   "payload":{  
      6      "EventDate":"2019-01-04T21:32:15.000Z",
      7      "AuthServiceId":null,
      8      "Platform":"Mac OSX",
      9      "EvaluationTime":0.0,
      10      "CipherSuite":"ECDHE-RSA-AES256-GCM-SHA384",
      11      "ClientVersion":"N/A",
      12      "LoginGeoId":"04F2J00006PqzoY",
      13      "LoginUrl":"login.salesforce.com",
      14      "LoginHistoryId":"0Ya2J0000Dt8t5aSQA",
      15      "CreatedById":"00550000001ZtKcAAK",
      16      "SessionKey":null,
      17      "ApiType":"N/A",
      18      "LoginType":"Application",
      19      “LoginSubType”:null,
      20      "PolicyOutcome":null,
      21      "Status":"Success",
      22      "AdditionalInfo":"{}",
      23      "ApiVersion":"N/A",
      24      "EventIdentifier":"eeccf731-2585-4a40-bfa5-770e31d6c2ab",
      25      "RelatedEventIdentifier":null,
      26      "SourceIp":"Salesforce.com IP",
      27      "Username":"joe.smith@acme.com",
      28      "UserId":"00550000001N45jAAC",
      29      "CreatedDate":"2019-01-04T21:32:19.188Z",
      30      "TlsProtocol":"TLS 1.2",
      31      "LoginKey":"QuEoTPHKy22V68XV",
      32      "Application":"Browser",
      33      "UserType":"Standard",
      34      "PolicyId":null,
      35      "SessionLevel":"STANDARD",
      36      "Browser":"Chrome 71"
      37   },
      38   "event":{  
      39      "replayId":2540
      40   }
      41}

Generally, don’t handle usernames and passwords of others when running code in production. In a production environment, delegate the login to OAuth. The BearerTokenExample.java class uses OAuth authentication.

Note