Our front end web application (Salesforce treated as background in this case) makes a call to Salesforce when customer submit an application. The application process might take upto 2 minutes , so the idea is to create a pushtopic where the front end application will subscribe to the topic when customer click a button. So in the meantime of 2 minutes web application engage with customer for other activities. After application process web application will let the customer know the results.

For each application submission it creates an Opportunity for a given customer account. So my query will look like

SELECT Id, Name, Status__c FROM Opportunity WHERE CreatedDate = TODAY and AccountId = "Customer Account ID(that exists in Salesforce already)"

Here AccountId is dynamic where each customer can have corresponding Accounts. How can I make my pushtopic SOQL dynamic. Some of my toughts are

1) When web application makes a call to Salesforce for Opportunity creation, in the apex code I can create the pushtopic as below as the system knows the AccountId at that time. But then If there are 100 customers submitting application through web portal I end up creating 100 Pushtopics. I am envisioning one PushTopic with dynamic AccountID as the input parameter. How can I achieve this?

PushTopic pushTopic = new PushTopic();
pushTopic.Name = 'ApplicationSubmission';
pushTopic.Query = 'SELECT Id, Name, Phone FROM Account WHERE AccountId=\'custAcntId\'';
pushTopic.ApiVersion = 43.0;
insert pushTopic;

2 Answers 2


I don't believe this is the intended way to utilize push topics. That is, creating a new PushTopic for each one off event that you are interested in and then deleting it after you receive the notification.

Instead, you could have a generic PushTopic that all the clients could subscribe to. Something with a query like:

SELECT Id, Name, Status__c, AccountID FROM Opportunity WHERE CreatedDate = TODAY

Then each client subscribes to this. When each message comes in the AccountID can be checked and then either processed further or discarded.

If there are 100 customers submitting via the web application there will be one push topic with 100 subscribers waiting to see a message with the expected AccountID.

It makes much more sense to send one event out to 100 subscribers than 100 events out to 100 individual subscribers.

Keep in mind the PushTopic Streaming Allocations, such as the maximum number of topics (40 - 100) and the maximum number of concurrent clients (subscribers) (20 - 2,000).

  • Thanks for the insight. I was able to achieve the requirement.
    – user28452
    Commented Jul 24, 2018 at 21:29

@crmprogdev, have you given using Platform Events a consideration.

You could leverage Platform Events in your solution in the following way.

  • The web application, posts the Opportunity creation request, to Salesforce.
    • Once, the Opportunity Creation Request is completed in Salesforce, an SubmissionComplete custom Platform Event is created with the details of the Opportunity and AccountId associated with the submission.
    • Your web application, can subscribe to this Platform Event type using the CometD API to autorefresh your page with the updated Application Submission Status details.

This could also save your web application the overhead of polling which I believe is one of the reasons why you opted to consider a Streaming API to listen to the application submission.

  • Can someone help me understand why a downvote since the solution posted was an alternative to the Streaming API approach?
    – Jigar Shah
    Commented Jul 18, 2018 at 8:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .