4

I am very new to salesforce streaming api. I am trying to get PushTopic notifications from salesforce for my custom object but I am not getting any idea about how should I start. Can you please provide me a starting point.

closed as too broad by Eric, Adrian Larson Feb 28 '17 at 6:04

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

1

There are pretty good examples in the documentation to get you started.

Assuming your custom object already exists the next step will be to create the PushTopic to indicate what you want to be notified of via the Streaming API.

PushTopic pushTopic = new PushTopic();
pushTopic.Name = 'InvoiceStatementUpdates';
pushTopic.Query = 'SELECT Id, Name, Status__c, Description__c FROM Invoice_Statement__c';
pushTopic.ApiVersion = 37.0;
pushTopic.NotifyForOperationCreate = true;
pushTopic.NotifyForOperationUpdate = true;
pushTopic.NotifyForOperationUndelete = true;
pushTopic.NotifyForOperationDelete = true;
pushTopic.NotifyForFields = 'Referenced';
insert pushTopic;

This example from Create a PushTopic will send out a streaming api event whenever the custom object Invoice_Statement__c is created/updated/undeleted/deleted (for the fields "Referenced" in the SOQL query). The payload in the event will be the fields in the SOQL query.

Now that you have something setup to generate events you just need to subscribe to the PushTopic Channel. The simplest starting point would be with Workbench. You can do a SOQL call against PushTopic to see what is available. Of particular interest in the Name field, which is what you will subscribe to.

From there the implementation would become Python specific. You will need to find a cometd client for Python. I use one for C#. The basic steps are:

  1. Create new Bayeus Client with an Authorization header where the value is "OAuth " and then the SessionId append to the end.
  2. Endpoint is something like http://instanceUrl.salesforce.com/cometd/37.0
  3. Perform Bayeux handshake
  4. Check in the CONNECTED state
  5. Subscribe to the channel of interest
  6. When asynchronous message events are raised check the channel Id and handle the JSON message payload appropriately.

Not the answer you're looking for? Browse other questions tagged or ask your own question.