+ Start a Discussion
Carter MellorCarter Mellor 

Recognise a community user on a force.com site

Is there a way to recognise a logged in community user on a force.com site? By recognise, I mean if a visualforce page or apex controller were to call a {!$User.FirstName} variable or something similar.
From what I can see, it looks like the site forces the everyone into the Guest user.
Andrew GAndrew G
You could check the UserLicense attribute on Profile

For Apex, something like:
User uObj = [Select id,Profile.UserLicense.Name from User where Id=: UserInfo.getUserId()];
Or using VF to display the current user license:
    <script src="../../soap/ajax/37.0/connection.js" type="text/javascript"></script>
    <script type="text/javascript">     
        var result= sforce.connection.query("Select Name,Id,Profile.UserLicense.Name from User WHERE Id = '{!$User.Id}'"); 
        var record1 = result.getArray("records");
        var userLicenseName = record1[0].Profile.UserLicense.Name;
        alert('userLicenseName ##'+userLicenseName );

Carter MellorCarter Mellor
Hi Andrew,

Sorry but that doesn't work. The UserInfo.getUserId() and {!$User.Id} are just getting the Guest User information. I want the user to be considered logged in, so I can get their Id with those calls.
Andrew GAndrew G
Hi Carter

In your first post you said that it was a "logged in community user", so i figured the above would work.  But I just re-read you comment about everything seeming to be passed to Guest user.  I might configure a test env with community and do some testing. 
Apologies for not reading correctly and messing your question.