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
Tyler Shobe 8Tyler Shobe 8 

LogoutEventStream not being recorded when user is forced logout after session timeout

Hello,

I'm attempting to create an apex trigger which fires off when a LogoutEventStream is created. Currently it works when a user physically logs out of an environment but does not when they are forced to logout because of a session timeout. According to Salesforce documentation, when "Force logout on session timeout" is enabled, a LogoutEventStream is recorded when a user is automatically logged out. See the second paragraph of the linked Salesforce article:

https://help.salesforce.com/s/articleView?id=sf.security_auth_create_logout_event_trigger.htm&type=5 (https://help.salesforce.com/s/articleView?id=sf.security_auth_create_logout_event_trigger.htm&type=5)

I have also included the trigger code as it exists now. As I mentioned, the trigger does what it is suppose to when manually clicking the Log Out button but does not when forced to logout after the end of a session timer which defies the documentation provided in the article above. If someone could help me identify how to resolve this issue by either ensuring LogoutStreamEvents are being properly recorded for forced logouts or providing a recommendation on how to achieve the execution of a trigger when a user is timeout of their session, I would greatly appreciate it.
 
trigger LogoutTrigger on LogoutEventStream (after insert) {
    LogoutEventStream event = 
        Trigger.new[0];
    Date todayDate = 
        System.today();
    List<Time_Card__c> timeCards = 
        [SELECT Id, Time_In__c 
         FROM Time_Card__c 
         WHERE OwnerId = :event.UserId 
         AND Date__c = :todayDate 
         AND Time_In__c != null 
         AND Time_Out__c = null 
         LIMIT 1];
    if (!timeCards.isEmpty()) {
        timeCards[0].Time_Out__c = System.now();
        timeCards[0].System_Clocked_Out__c = TRUE;
        update timeCards[0];
    } 
}



Thank you!
Clara GauntClara Gaunt
Hi. I'm also experiencing this while trying to do the same in my org. Did you find a resolution to this in the end?