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.
-
Open the Developer Console.
-
Click Debug | Open Execute Anonymous Window.
-
In the Enter Apex Code window, paste in the following Apex code, and click Execute.
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.Because
NotifyForOperationCreate,NotifyForOperationUpdate,NotifyForOperationDeleteandNotifyForOperationUndeleteare set totrue, Streaming API evaluates records that are created, updated, deleted, or undeleted and generates a notification if the record matches the PushTopic query. BecauseNotifyForFieldsis set toReferenced, Streaming API will use fields in both the SELECT clause and the WHERE clause to generate a notification. Whenever the fieldsName,Status__c, orDescription__care updated, a notification will be generated on this channel. For more information aboutNotifyForOperationCreate,NotifyForOperationUpdate,NotifyForOperationDelete,NotifyForOperationUndelete, andNotifyForFields, 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, andNotifyForOperationUndeletefields are unavailable and theNotifyForOperationsenum field is used instead to set which record events generate a notification. For more information see PushTopic.