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
SudhanwaSudhanwa 

Finding out if the logged in user is from United States

Hi all,

 

I have a requirement where in I should identify if a user is from United States region. There is a download button which should allow only users from US to download files. Is this achievable through Apex? Or, should it be done via javascript? Can you please tell me how?

 

Thanks in anticipation.

 

-Sudhanwa.

hisrinuhisrinu

If you are talking about login history then you will not be able to access that information through Apex

SudhanwaSudhanwa

I am talking about the time when the user clicks on 'download' button, he/she should be able to do it only if in US. Otherwise, no download should be possible.

 

-Sudhanwa.

Pradeep_NavatarPradeep_Navatar

Try the sample code give below :

 

User u = [select localsidekey.communitynickname,lastname,firstname from user where id=:userinfo.getuserid()];

 

Hope this helps.