3

So we use after insert trigger on "LogoutEventStream" for some actions on logout.

My question is about, how to write tests for this? How do we call the insert record on LogoutEventStream?

Here's the link to the actual trigger https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_logouteventstream.htm

2

2 Answers 2

2

here is the solution for unitTest:

 Test.startTest();    
 EventBus.publish(new LogoutEventStream());
 Test.stopTest();

Hope this helps others with same issue

0

Add this in your test class :

   @isTest
   public static void scenario1(){
       User u = new User();
       u.Email = '[email protected]';
       u.Username = '[email protected]';
       u.MobilePhone = '1234567890';
       u.CommunityNickname = 'testssf';
       Profile p = [SELECT Id,Name FROM Profile WHERE Name = 'System Administrator'];
       p.PermissionsCustomizeApplication  = True;
       u.ProfileId = p.id;
       u.LastName = 'test';
       u.Alias = 'tstsfsf';
       u.TimeZoneSidKey = 'Asia/Kolkata';
       u.LocaleSidKey = 'en_US';
       u.LanguageLocaleKey = 'en_US';
       u.EmailEncodingKey = 'UTF-8';
       u.IsActive = True;
       insert u;
       
       Test.startTest();
       User u1 = [SELECT Id, IsTeamMemberActive__c, UserName FROM User WHERE Id =:u.id];
       LogoutEventStream event = new LogoutEventStream();
       event.UserName = u1.UserName;
       EventBus.publish(event);
       Test.stopTest(); 
   }

You must log in to answer this question.

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