You need to sign in to do that
Don't have an account?
Tan J
Best optimized way to get logged in user info and set variables in apex controller
I want to know the best optimized way to access current logged in user's information and set few flags. I have a controller extension and I have set flags in constructor like this:
User u = [SELECT ID,Name,ProfileID,Profile.Name,UserRole.Name,UserRole.ID,Team_Lead__c,Leading_Teams__c,Department,Desk__c
FROM User
WHERE id=:userId];
if(u.UserRole.Name != null && u.UserRole.Name.contains('xyz')){
isComUser = true;
}
if(u.UserRole.Name != null && u.UserRole.Name.contains('pqr')) {
isFPUser = true;
}
...and the conditions go on..
There are so many conditions that constructor has become really big & unmanagable.
Is there a good way to do this? Thanks in advance
User u = [SELECT ID,Name,ProfileID,Profile.Name,UserRole.Name,UserRole.ID,Team_Lead__c,Leading_Teams__c,Department,Desk__c
FROM User
WHERE id=:userId];
if(u.UserRole.Name != null && u.UserRole.Name.contains('xyz')){
isComUser = true;
}
if(u.UserRole.Name != null && u.UserRole.Name.contains('pqr')) {
isFPUser = true;
}
...and the conditions go on..
There are so many conditions that constructor has become really big & unmanagable.
Is there a good way to do this? Thanks in advance
If its your Visualforce page, you can directly use either user instance or global VF variable !$User.
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_variables_global_user.htm
Any ideas on this would be appreciated.