Step 2: Create a PushTopic (Legacy)

Create a PushTopic in the Developer Console. Event notifications are generated for updates that match the query.

PushTopic events is a legacy product. Salesforce no longer enhances PushTopic events with new features and provides limited support for this product. Instead of PushTopic events, consider using Change Data Capture events. To subscribe to change events, see Java Quick Start for Pub/Sub API in the Pub/Sub API Guide. To learn about Change Data Capture, see the Change Data Capture Developer Guide and the Change Data Capture Basics Trailhead module.

Important

  1. Open the Developer Console.
  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 = 64.0;
    pushTopic.NotifyForOperationCreate = true;
    pushTopic.NotifyForOperationUpdate = true;
    pushTopic.NotifyForOperationUndelete = true;
    pushTopic.NotifyForOperationDelete = true;
    pushTopic.NotifyForFields = 'Referenced';
    insert pushTopic;

    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.

    Note

    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.

    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.

    Note