Is there any way to mock and test Salesforce Streaming? How do you test Salesforce Streaming API ?

  • Be a bit more explicit here - what/who are the subscribers/consumers of the stream?
    – cropredy
    Dec 10 '19 at 18:52

Yes. It is possible.

 @isTest static void testPlatformEvent() {
        SomeEvent__e event = new SomeEvent__e(SomeField='test');

        Database.SaveResult sr = EventBus.publish(event);

        System.assertEquals(true, sr.isSuccess());

For more information read Salesforce guide

  • this testmethod, while correct, actually tests nothing of interest. By definition, EventBus.publish(event) will always work in the test context provided you are not publishing more than 500 events. Consumption of the event is what one would test in a testmethod and that requires the org to have a subscriber (trigger/PB/flow) that leaves some persistence behind to asset against
    – cropredy
    Dec 10 '19 at 18:51

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.