Apisero is now part of NTT DATA - Learn more.

Search
Close this search box.

Capture Last Logout In Salesforce

Author: Rishabh Dubey

Salesforce provides the Last Login on the user detail page however there is no out-of-the-box feature for the Last logout in Salesforce.

1. LogoutEventStream and a trigger can be used to meet this requirement
  1. Enable Streaming for Logout Stream
  2. Go to setup
  3. Search for Event Manager
  4. Enable Streaming for Logout Event
2. Create a Last logout (Date/Time) field on the User Object
  1. Go to setup then object manager
  2. Open user Object
  3. Click on fields and relationship
  4. Click on New
  5. Select Date Time as the data type
  6. Give the label “Last logout”
  7. Select FLS and add it to the page layout
3. Create the below trigger on LogoutEventStraem Object
trigger Logoutinfo on LogoutEventStream (after insert) {

    List <User> userList= new List <User>();

for( LogoutEventStream les:Trigger.new)

{

  for(User userInfo: [Select ID,Last_Logout__c From User where ID =: les.UserID] ) 

  {  

  userInfo.Last_Logout__c=System.now();

  userList.add(userInfo);  

  } 

}

     update userList;

}
4. Test your Automation
  1. Log out from UI.
  2. Login again and open your user record.
  3. The last logout field should be updated by the time when you clicked Logout.

Note: This Automation will only show logouts done by UI, not from Session Time out.

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.