You need to sign in to do that
Don't have an account?
Ashwin Kumar 80
10 Users loginhistory using Maps
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.
please help me.
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.
Just try below code,
Thanks,
All Answers
Just try below code,
Thanks,
It working as expected, Thanks for the help :) .
Regards,
Ashwin