• Ashwin Kumar 80
  • NEWBIE
  • 10 Points
  • Member since 2018

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

I want to get 10 users last 10 days loginhistory using map collection.
I am trying with below code, But I am not getting expected result . please help me.
 
Map<Id,User> users =new Map<Id,User>([Select Id from User Limit 10]) ;
system.debug('Users-->'+users);
Map<Id,List<LoginHistory >> loginDetals = new Map<Id,List<LoginHistory >>();
for(String uIds : users.keySet()){
    loginDetals.put(uIds , [SELECT Id, UserId,LoginTime from LoginHistory where UserId=:uIds and LoginTime=LAST_WEEK]);
	system.debug('put in map-->'+loginDetals);
    }
 
set<id> uIds= new set<id>();
for(User ac: [Select id from User limit 10]){
    uIds.add(ac.id);
}
system.debug('Users-->'+uIds);
Map<Id,List<LoginHistory >> loginDetals = new Map<Id,List<LoginHistory >>();
List<LoginHistory> LHList = [SELECT Id, UserId,LoginTime from LoginHistory where UserId=:uIds and LoginTime=LAST_WEEK Limit 50000 ];
system.debug('Login Details-->'+LHList);
for(LoginHistory lh:LHList)
{    If(!loginDetals.ContainsKey(lh.UserId))
    {
        loginDetals.put(lh.UserId,new List<LoginHistory>{lh});
        system.debug('put in map-->'+loginDetals);
    }
}

please help me.
Hi,

I want to get 10 users last 10 days loginhistory using map collection.
I am trying with below code, But I am not getting expected result . please help me.
 
Map<Id,User> users =new Map<Id,User>([Select Id from User Limit 10]) ;
system.debug('Users-->'+users);
Map<Id,List<LoginHistory >> loginDetals = new Map<Id,List<LoginHistory >>();
for(String uIds : users.keySet()){
    loginDetals.put(uIds , [SELECT Id, UserId,LoginTime from LoginHistory where UserId=:uIds and LoginTime=LAST_WEEK]);
	system.debug('put in map-->'+loginDetals);
    }
 
set<id> uIds= new set<id>();
for(User ac: [Select id from User limit 10]){
    uIds.add(ac.id);
}
system.debug('Users-->'+uIds);
Map<Id,List<LoginHistory >> loginDetals = new Map<Id,List<LoginHistory >>();
List<LoginHistory> LHList = [SELECT Id, UserId,LoginTime from LoginHistory where UserId=:uIds and LoginTime=LAST_WEEK Limit 50000 ];
system.debug('Login Details-->'+LHList);
for(LoginHistory lh:LHList)
{    If(!loginDetals.ContainsKey(lh.UserId))
    {
        loginDetals.put(lh.UserId,new List<LoginHistory>{lh});
        system.debug('put in map-->'+loginDetals);
    }
}

please help me.