function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
lalitaroralalitarora 

Test class for logout event stream?

trigger LogoutEventTrigger on LogoutEventStream (after insert) {
    
    LogoutEventStream event = Trigger.new[0];
    String EventjsonString = json.serialize(Trigger.new[0]);
    LogoutEventtriggerHandler.CreateLog(EventjsonString);    
    
}
Agustin BAgustin B
Hi lalitarora, try with this code please:
@IsTest
    private static void test(){
Test.startTest();
EventBus.publish(new LogoutEventStream());
Test.stopTest();}

If it helps please like and mark as correct, it may help others.
상일 정 3상일 정 3

Hi Agustin,

When I wrote a test class about LogoutEventStream, I got an error below.
System.TypeException: DML operation INSERT not allowed on LogoutEventStream
I definitely use the code 'EventBus.publish(new LogoutEventStream());'

What's the problem?

Tony Kirumba 3Tony Kirumba 3
Any update on this? I would also like to test logouteventstream triggers and ran into the same problem as 상일 정 3 above
Kamil TyszkiewiczKamil Tyszkiewicz
@IsTest
static void testLogoutEventStream() {
User automatedProcessUser = [SELECT Id FROM User WHERE Name = 'Automated Process' LIMIT 1][0];
User testUser = new User(...);
System.runAs(automatedProcessUser) {
Test.startTest();
EventBus.publish(new LogoutEventStream(UserId = testUser.Id));
Test.stopTest();
}
}