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
Lucas IslaLucas Isla 

How to tell whether user is in Community or main Salesforce site

Hi,

I am trying to show special header and footer components on a Visualforce page if the user is logged into the Community.
Otherwise, if the user is just on the main Salesforce site, I want to render the page without the header and footer.

Is there an easy way to get the context of the user from within the Visualforce page to conditionally render these components based off of this?
Thanks
PawanKumarPawanKumar
As per my understanding, there is no standard way to get it. But you can go with below utility code where it checks logged in user Profile.

Profile pfile = [Select Name from Profile where Id =: userinfo.getProfileid()];
String pname = pfile.name;
System.debug(pname);

Boolean isCommunityUser = false;
if(pname == 'Customer Community User') {
isCommunityUser = TRUE;


if(isCommunityUser){
// show header footer
}

You can replace 'Customer Community User' with your community Profile name.