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
johncusackjrjohncusackjr 

Is there a Customer Portal Flag?

Hi all,

 

How can I tell my Visualforce page is accessed from customer portal?
Is there a profile, permission or system flag that i can check?

 

Thanks,

John

Pradeep_NavatarPradeep_Navatar

This can be achieved by using the  SOQL query in apex. Go through the sample code given below :

 

User usr = [Select ContactId, Profile.Name,IsPortalEnabled from user where Id=: UserInfo.getUserId()];

if (usr.IsPortalEnabled  = true){// your business logic here}

 

Hope this helps.

johncusackjrjohncusackjr

Thanks

johncusackjrjohncusackjr

Hi again Pradeep,

 

Your suggestion didn't solve the problem for Professional Edition accounts.

When my customers try to install the application that check fails in Professional Edition:

 

User usr = [Select ContactId, Profile.Name,IsPortalEnabled from user where Id=: UserInfo.getUserId()];

if (usr.IsPortalEnabled  = true)

{

// your business logic here

}

 

I tried this in System Log of a Professional account:

User usr = [Select IsPortalEnabled from user where Id=: UserInfo.getUserId()];
System.debug('Customer Portal user' + usr.IsPortalEnabled);

 

and got this error:

Compile Error: line 1, column 12: No such column 'IsPortalEnabled' on entity 'User'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

 

But this works flawlessly on a Enterprise/Developer account.

 

Do you have any other suggestion to fix this?

 

Thanks,

John

gitguygitguy
Did you ever get an answer to this? I'm having the same issue. How can I tell which SOQL to use before using it?
johncusackjrjohncusackjr

 


Tom G wrote:
Did you ever get an answer to this? I'm having the same issue. How can I tell which SOQL to use before using it?

I found below workaround in Apex

public Boolean getIsCustomerPortalUser()
    {
        String restrictedPortalUserTypeValues =  'Customer Portal User,High Volume Portal,Customer Portal Manager';
		// You can get from custom setting or other config file 
          
        Boolean customerPortalUser = false;
        String userType = UserInfo.getUserType();
        
        List<String> restrictedValues = null;
        if(restrictedPortalUserTypeValues != null && restrictedPortalUserTypeValues != '')
        {
            restrictedValues = restrictedPortalUserTypeValues.split(',');   
            for(Integer i = 0; i < restrictedValues.size(); i++)
            {
                if(userType == restrictedValues[i])
                {
                    customerPortalUser = true;
                    return customerPortalUser;
                }
            }
        }
        else
        {
            if(userType != 'Standard')
            {
                customerPortalUser = true;
            }
        }
        return customerPortalUser;
    }

 You can find list of User Type's in http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_user.htm

 

Thanks,

John