• eswar prasad
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi,

My requirement is to show logged in users all the articles published after their respective last login date.
Since, the last login date is updated as soon as user logs in, I'm unable to get the date prior to that.
I tried using LoginHistory object, but for running soql on LoginHistory object, "Manage Users" permission is required. Since this permission can not be provided to all the users, this can not be considered as option.
Please find the code below:
//CurrentLoginTime as user is already logged in
DateTime currentLogin = [SELECT LastLoginDate FROM User WHERE Id =:UserInfo.getUserId()].LastLoginDate ; 
//Any prior login time before the current login time
DateTime lastLogin = [select loginTime from LoginHistory where userId = :UserInfo.getUserId() and loginTime != :currentLogin order by LoginTime Desc limit 1].loginTime;
I have also tried to make the class "without sharing", it throws an exception.
Many thanks in advance for the help.

Regards,
Shekhar