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
Sai Teja 7557Sai Teja 7557 

How to differentiate between the logged in User vs Guest User on Experience Cloud sites(communities)

I have a visualforce page, which is published on communitis(public page),once they opened the page we are taking some inputs and creating the user with those details and redirecting to the login page and asking to login. once they login we need to open the same visualforce page and need to show other fields for entering the inputs.

"So here we need to apply some conditions to render some fields for guest user and some other fields for logged in user."

My Question is there any way to identify the the page viewer is guest user or logged in user..

 
VinayVinay (Salesforce Developers) 
Hi Sai,

You can try below code to check.
 
public static Boolean fetchUserType() {
        Boolean isLoggedIn = false;
        String userType = UserInfo.getUserType();
        if (userType != 'Guest') {
            isLoggedIn = true;
        }
        return isLoggedIn;
    }

https://salesforce.stackexchange.com/questions/1987/how-to-tell-if-a-user-is-authenticated-in-a-sites-visualforce-page

Thanks,