0

I just stumbled upon something while using $A.get("$SObjectType.CurrentUser.Id") to get current user id in lightning component.
$A.get("$SObjectType.CurrentUser.Id") returns Id only if user is logged in and is not guest user. In case of Guest user, undefined is returned. Is that an intended behavior or just another bug in Salesforce.

2

This is very much intended behavior, as the Guest user in Salesforce is intended user for Salesforce Sites without the need to login. Here are few features related to guest user

Guest user licenses are required for force.com sites. EE/UE orgs are allowed to create up to 25 sites hence the 25 guest user licenses.

  1. Each site has a special user with a user type called guest user type
  2. Guest users have no password, no role and have no API access on their profile.
  3. You can't login or do client side api call (only within apex code).
  4. There is no session for guest browsing
  5. Each guest user (site) has a unique profile (public access settings)
  6. These profiles are associated to guest user licenses which give the ability to read/create on standard objects and full CRUD on custom objects. However, by default no CRUD is given. Admins needs to enable the right level of access based on their flow
  7. We advise private sharing for the objects that are enabled for sites
  8. Guest user licenses can't be used for any other purposes other than Force.com Sites.

Since, the guest users have no session/login information, therefore the method $A.get("$SObjectType.CurrentUser.Id") returns undefined. You would also get Null or error if you try to fetch user Id in Apex or VF for guest user.

VF page: {!$User.Id}

Apex: UserInfo.getUserId()

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.