Newer Version Available

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

Step 2: Create a PushTopic

Use the Developer Console to create the PushTopic record that contains a SOQL query. Event notifications are generated for updates that match the query.
  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.
    1PushTopic pushTopic = new PushTopic();
    2pushTopic.Name = 'InvoiceStatementUpdates';
    3pushTopic.Query = 'SELECT Id, Name, Status__c, Description__c FROM Invoice_Statement__c';
    4pushTopic.ApiVersion = 57.0;
    5pushTopic.NotifyForOperationCreate = true;
    6pushTopic.NotifyForOperationUpdate = true;
    7pushTopic.NotifyForOperationUndelete = true;
    8pushTopic.NotifyForOperationDelete = true;
    9pushTopic.NotifyForFields = 'Referenced';
    10insert 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