You need to sign in to do that
Don't have an account?

How to return all the accounts that a user has acces to view based on the userID and role
I want to return all the accounts a user has and has access to see for a specific role otherwise to return only the accounts the he has
I tried something like this but is not working
System.Debug(UserInfo.getUserRoleId());
if((UserInfo.getUserRoleId()).equals('BOSS')|| (UserInfo.getUserRoleId()).equals('BOSS 2')){
return [SELECT id, name, AccountStatus__c, OwnerId,
FROM Account
LIMIT:100000];
}else {
return [SELECT id, name, AccountStatus__c, OwnerId,
FROM Account
WHERE OwnerId =: UserInfo.getUserId()
LIMIT:100000];
I tried something like this but is not working
System.Debug(UserInfo.getUserRoleId());
if((UserInfo.getUserRoleId()).equals('BOSS')|| (UserInfo.getUserRoleId()).equals('BOSS 2')){
return [SELECT id, name, AccountStatus__c, OwnerId,
FROM Account
LIMIT:100000];
}else {
return [SELECT id, name, AccountStatus__c, OwnerId,
FROM Account
WHERE OwnerId =: UserInfo.getUserId()
LIMIT:100000];
All Answers