Newer Version Available

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

Step 4: Use a Visualforce Page to Generate and Replay 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:
  • A particular event by supplying the event’s 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.
  1. To open the Visualforce page in your browser, delete the portion of the URL after your Salesforce instance and append /apex/StreamingDurableGenericDemo. The URL you navigate to looks like the following: https://Salesforce_Instance/apex/StreamingDurableGenericDemo.

    Alternatively, you can access and preview your Visualforce pages from Setup or the Developer Console.

    Note

  2. In the Visualforce page, generate some events. Enter any text for the message text, for example, Test message. For Number of Events, enter 10.
  3. Click Generate.

    The page subscribes to all events by default (-2) and displays them in the Notifications section.

    Note

  4. 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.
    Visualforce sample that generates and replays past events
  5. 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.
  6. 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.
    Visualforce sample that generates and replays past events