You need to sign in to do that
Don't have an account?
Nikhil Garg 17
Subscribe platform event in vf page
Hi Team,
I got stuck in one problem, Actuallly I need to send data from my apex class to vf page using platform events, but I'm stuck in how to subscribe my platform event in my vf page and get data.
kindly give soultion for the same.
I got stuck in one problem, Actuallly I need to send data from my apex class to vf page using platform events, but I'm stuck in how to subscribe my platform event in my vf page and get data.
kindly give soultion for the same.
Can you please elaboarte more about this use case. Till then sharing a code snippet which might help you.
You need to insert platform Event record in apex class:
And you can subscribe the event in vf page:
You can get the static resource for cometd from the link below:
https://developer.salesforce.com/page/Streaming_Real_Time_Data_into_Visualforce
Let me know if this helps.
Thanks,
Sukanya Banekar
Please review this discussion too -> https://salesforce.stackexchange.com/questions/298863/subscribing-to-a-platform-event-in-a-vf-page-that-is-a-part-of-a-force-com-site
Thank you.
Hi Sukanya,
Thanks for your response. so my use case is
"I have a VF page that is calling the method of apex class, Apex class is looping over something but to overcome Apex CPU Time error I have break loop in batches and each batch is running as an Async transaction, I want that whenever an async class is called for every batch from apex class, the async class must return some response to the apex class. Because my apex class is returning responses to the vf page for some operations. But async classes can't return anything.
So I thought to follow the approach that, I can use Platform events to return an async class response to my vf page. so after processing of async class, it will publish my response using the platform event and I'll subscribe platform event on the vf page."
The code you have provided may work but I'm not able to find libraries of these APIs so that I can store them as a static resource.
Kindly help, if you find something different for this use case.
Thanks & Regards
Nikhil Garg
You mean to say JS and cometd libraries?
Yes please share the links to download these libraries and the link you have shared for the cometD is not working.
If you have other approach for my use case then kindly suggest.
Thanks