+ Start a Discussion
Saurabh Kulkarni 84Saurabh Kulkarni 84 

Subscribe to Streaming API in lightning component

Hello everyone, 

​​​​​I'm trying to use streaming API in lightning component. For which I have added EMP API. This works well for me.

Now, I have custom object which allows user to create some new records and based on which a new channel is created from apex. This record also specifies a list of users who are expected subscribers to this newly created channel. The problem is that the users while being on some page where my lightning component is added cannot get auto subscribed to this newly created channel. Users will have to reload the component (using page reload or refresh) so that I can query new channels and make them auto subscribed on load. I want to remove this dependancy so that users can somehow get auto subscribed to a newly created channel without reload. Is there any way we can do this? 

Thank you in advance 
Saurabh Kulkarni 
AnudeepAnudeep (Salesforce Developers) 
Hi Saurabh, 

There will not be a "native" way to do this.
 
This would likely be fairly hard to build, but you could create a channel where you would publish an event that says a new channel has been created, and then build the logic in your app to decide if you should add the subscription-based on the running user.
 
I would say that the use case seems odd since I would not expect a lot of new channels to be created. If you are creating push topics, this will likely eventually slow your system down (since we have to evaluate each record on each channel) and with Generic STreaming it seems like you could just use user targeting instead of creating new channels.

Anudeep
Saurabh Kulkarni 84Saurabh Kulkarni 84
Thank you so much Anudeep for your response.

It's not necessary for me to create a channel everytime. I can have one channel being associated with all records which are getting created in that custom object which holds the list of potential subscribers. 

​​​​​The only problem then I have to live with it is that there can be only limited number of subscribers at a time, if I understand the limitations correctly. Hence, I cannot make all people in the org subscribed to a channel all the time on first load and then the custom object record sending event to only some of them. I wanted to see if I can make only those people subscribe automatically when a new custom object record is created and the user's name is present in the list. 

Is there any way for this? 

Appreciate your help on this. 

Thanks,
Saurabh Kulkarni