We have an implementation in which there are multiple Visualforce pages(seven pages). These pages are using platform events to communicate between each other. The JavaScript code to subscribe to events in all the Visualforce pages looks like below:

cometd.subscribe('/event/platform_event__e', function(message) {
    // Code to display warning message to user

Main issue that we are seeing is - the callback function given in subscribe is not called every time the event is published from another page.

We had tested this and it was working fine a few days ago but it stopped working since a few days. This happened even though no changes were done to the code that may affect the cometd subscription in Visualforce page.

Note that we are using SFDX so all this code development and testing is being done in scratch orgs.

While troubleshooting the issue, we came across the following error in the browser console: "403::Organization concurrent user limit exceeded" - this error is being returned when cometd tries to do a handshake to establish a connection to server. Due to this, the handshake fails and the connection is not established.

This limit looks like the limit mentioned in "Common Platform Event Allocations" given in the documentation. As per this limitation, the scratch org has a limit of 20 for "Maximum number of concurrent CometD clients (subscribers) across all channels and for all event types." which is not the case for Enterprise or higher edition orgs. So we tried to reproduce this issue in an Enterprise edition org where the limit for this was 1000. Above code did NOT work even in Enterprise edition org and it did not give the error for concurrent user limit as mentioned above.

To solve this, we changed the cometd subscription code in JavaScript as follows:

cometd.addListener('/meta/handshake', function(message) {
    cometd.subscribe('/event/platform_event__e', function(message) {
        // Code to display warning message to user

This change ensures that every time a handshake call is done, the client subscribes again to the given channel.

This solved the issue in Enterprise edition org but we are still seeing the issue of "403::Organization concurrent user limit exceeded" in the scratch org. In the scratch org, we also checked the cometd connection status on each Visualforce page at specific intervals and connections on some pages were randomly disconnected and never connected back. This was due to the same handshake error mentioned above.

When we check the limits consumption in workbench using /limits api, in "DurableStreamingApiConcurrentClients" property it shows enough remaining units for concurrent users but browser console shows this error.

So there are two issues that we found: 1. The code stopped working without any changes to the code. 2. The new code works but not in scratch orgs even though the limit is not exceeded.

Can someone provide some inputs on this? Are we missing something?

| improve this question | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.