How to Capture Salesforce User Logout Activity – LogoutEventStream

LogOut Event Detail Records

Hi Everyone, Welcome again ;). In this tutorial, we are going to learn how we can capture the Logout Event. We can perform any operation after user Logout like we can create the LogOut event records to track how many hours a user is working or logging hours.

To capture the Logout Event, you need to Enable “Enable Logout Events Stream” setting under “Session Setting”.

Enable Logout Events Stream is a beta feature and to make this available for your org you need to contact Salesforce Support. Once they will enable the setting then you can enable the Setting and Develop the Trigger on the LogOutEventStream Object.

Once You have contacted your salesforce support and then have enabled the option. Follow the below steps.

Go to Setup -> Session Setting –> Scroll Down till “Logout Events” section and Check “Enable Logout Events Stream” Checkbox.

Create a New Custom Object to Store the Logout Event

Now, as you have created the Custom object to Store the Events create a Trigger and use below code for the trigger

trigger LogoutEventTrigger on LogoutEventStream (after insert) { 
    List<LogoutEvent__c> eventList = new List<LogoutEvent__c>();
    For(LogoutEventStream event : Trigger.new){
        LogoutEvent__c record = new LogoutEvent__c();
        record.EventIdentifier__c = event.EventIdentifier;
        record.UserId__c = event.UserId;
        record.Username__c = event.Username;
        record.EventDate__c = event.EventDate;
        record.RelatedEventIdentifier__c = event.RelatedEventIdentifier;
        record.ReplayId__c = event.ReplayId;
        record.SessionLevel__c = event.SessionLevel;
        record.SourceIp__c = event.SourceIp;
        record.SessionKey__c = event.SessionKey;
        record.LoginKey__c = event.LoginKey;
        eventList.add(record);
    }
    insert eventList;
}

Now, go ahead and Log out. Login again and go to the object and you will be able to see the logout event record.

Sharing is caring 🙂 😉 Keep learning. Happy Trailblazing.

Resources: –

5 thoughts on “How to Capture Salesforce User Logout Activity – LogoutEventStream

Leave a Reply

Your email address will not be published. Required fields are marked *