function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vivekh88Vivekh88 

Profile name from LoginHistory using SOQL

Hi,
I have a requirement where i need to get the total count of Logins done by the particular profile.

Profile                                      Month                       Times Logged in
System Administrator                August 2016              150
Standard User                          August 2016               123


I tried to give this query,
List<Aggregateresult> logquery = [Select count(LoginTime) logintime, userid from LoginHistory where userid =: scope Group by userid];

But this wil execute the total count by Users. But i need it for Profiles. Is there any other workaround to do this?

Thanks
Vivekh
 
SinghforceSinghforce
Hi Vivek,

The problem with Login History is we cannot traverse to parent object. Instead of this, you can try:

SELECT count(id), Profile.Name FROM User where LastLoginDate <= today group by Profile.Name

This will give you the count of logged in users against the profiles.

Pls mark this answer if it solves your query.

Thanks,
Dilip Singh