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
Azzu3 ShaikAzzu3 Shaik 

Browser name of logged in User.

Hi All,
Is there any way to find out the Browser name of logged user . If yes ,can any one help me out how to query it.


Thanks,
KaranrajKaranraj
You can able to query using LoginHistory object in salesforce, check this link - https://www.salesforce.com/developer/docs/api/Content/sforce_api_objects_loginhistory.htm
SELECT UserId, LoginTime from LoginHistory where UserId= 'Looged in user id';

 
Vivek_PatelVivek_Patel
Hi,

More refined version to get the Browser name of the logged in user.
SELECT Browser FROM LoginHistory WHERE UserId = :UserInfo.getUserId() ORDER BY LoginTime DESC LIMIT 1

There are multiple records for a single user, so better approach would be if you query the records for that user wit Status field which actually shows if the login was successful or not and then get the correct record's browser field.

Limitation here is you can't user Status field in the query criteria, so you will have to handle that in your class after querying Status field.

Regards,
Vivek Patel.