You need to sign in to do that
Don't have an account?
Validation based on current users custom field
Hi,
I'm trying to introduce validation on one of our apex classes which is based on a custom field value on the user's record.
So we have a custom field setup on the user object called Consultant (checkbox).
When a user logs in I want to return an error message if that current logged in user has Consultant = FALSE then show them the error message whereas for users where Consultant = TRUE they can bypass the error.
List<User> lstUser = [Select Agent_Name__c from User where userinfo.Consultant__c=TRUE];
if(lstUser.size()==0 ){
apexpages.addmessage(new ApexPages.Message(ApexPages.severity.FATAL,' You can not proceed'));
When I try using userinfo. it doesn't compile so does anyone know how to retrieve a value from a custom field on user object for the current user?
Try this code snippet:-
String ids=userinfo.getUserId();
List<user>usr=[Select Agent_Name__c from User where Consultant__c=TRUE And ID=:ids];
if(lstUser.size()==0 ){
apexpages.addmessage(new ApexPages.Message(ApexPages.severity.FATAL,' You can not proceed'));
Thanks
Anil.B
All Answers
Try this code snippet:-
String ids=userinfo.getUserId();
List<user>usr=[Select Agent_Name__c from User where Consultant__c=TRUE And ID=:ids];
if(lstUser.size()==0 ){
apexpages.addmessage(new ApexPages.Message(ApexPages.severity.FATAL,' You can not proceed'));
Thanks
Anil.B