Skip to main content
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>
1 respuesta
  1. 11 feb 2021, 15:07
    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
0/9000