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;