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
Ramana123Ramana123 

Display error message when I open the visualforce page (login to the second user)

when open the visualforce page using the second user ,then throw an error message (stored second user id in custom label) , but it is not coming 
 
apex class :

public class Differentiating_Vfpages_Based_on_User
{
    List<ApexPage> vfPageId {get;set;}
    public String Userid {get;set;}
    public  Differentiating_Vfpages_Based_on_User()
    {
             Userid = UserInfo.getUserId();        
             if(Userid == System.Label.UserId )
                 
                   {
                   ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'You have no access'));
                   }  
        
        System.debug(System.Label.UserId);
    }   
}


apex page


<apex:page controller ="Differentiating_Vfpages_Based_on_User">
    <apex:form>
    <apex:pageblock>
        
    </apex:pageblock>
    </apex:form>
</apex:page>
SwethaSwetha (Salesforce Developers) 
HI Srikanth,
 You need to include the apex:pageMessages tag for the warning to work.Your VF code can be changed as below
<apex:page controller="Differentiating_Vfpages_Based_on_Use">
    <apex:form >
    <apex:pageblock >
        <apex:pageMessages id="showmsg"></apex:pageMessages>
        HELLO
    </apex:pageblock>
    </apex:form>
</apex:page>
Also, you need to make sure that the value of userid in the custom label is 18 digits. You can add a debug statement like below in your apex class to understand the values

system.debug('Userid in custom label==='+System.Label.UserId+'Userid of logged in user==='+Userid);

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you