1

I am trying to create a external client to publish Platform events to Salesforce event bus. I have used REST API to do the same but I wanted to do it via a true 'Publish'. My guess is that this will not count towards API quota. Is this even possible? I know that listening is possible (using CometD.NetCore.Client) but found no help on Publishing to Salesforce Platform event using the same. Can someone please help?

Here is my code in C#:

        var bayeuxClient = new BayeuxClient(endpoint, new[] { transport });
        bayeuxClient.Handshake();
        bayeuxClient.WaitFor(1000, new[] { BayeuxClient.State.CONNECTED });
        if(!bayeuxClient.Connected)
        {
            return;
        }

        var channel = bayeuxClient.GetChannel(topic);
        if(channel == null)
        {
            return;
        }

        //channel.Publish("{\"Payload__c\" : \"Some message\"}");// does not do any publishing

        channel.Subscribe(new Listener());//this works and I get notified when there is a new plat event

Thanks

2 Answers 2

3

You can't push a message to Salesforce event bus through CometD. From the doc:

Streaming API supports the following CometD methods:

  • connect The client connects to the server.
  • disconnect The client disconnects from the server.
  • handshake The client performs a handshake with the server and establishes a long polling connection.
  • subscribe The client subscribes to a channel defined by a PushTopic. After the client subscribes, it can receive messages from that channel. You must successfully call the handshake method before you can subscribe to a channel.
  • unsubscribe The client unsubscribes from a channel.
2

We can publish event to Salesforce EventBus from an external application by making use of API only.

You can use any Salesforce API to create platform events, such as SOAP API, REST API, or Bulk API.

To publish a platform event message using REST API, send a POST request to the following endpoint:

/services/data/v49.0/sobjects/Event_Name__e/

For More Details: https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_publish_api.htm

You must log in to answer this question.

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