You need to sign in to do that
Don't have an account?
Ramana123
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>
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>
You need to include the apex:pageMessages tag for the warning to work.Your VF code can be changed as below 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