function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sslatersslater 

using profile.permission* in where clause

I was trying to make a soql call like:

 

Select u.Email, u.Id, u.Name, u.ProfileId, u.Profile.Name, u.Profile.PermissionsViewAllData from User u where u.Profile.PermissionsViewAllData = true

 

and it gave me an error saying that I cannot use the Permissions* in a where clause.

 

Does anyone know why and/or if you can work-around this? Seems kinda silly. I know I can just query for everything and then handle it in apex, but that's not as clean.

 

Thanks!

tmatthiesentmatthiesen

Salesforce does not let you filter on Profile.PermissionsViewAllData. I would use this instead: //assuming I understand your requirements...

 

list<profile> ps = new list<profile>();

list<user> us = new list<user>();

 

ps = [Select Name, PermissionsViewAllData, (select user.id from Profile.Users) from Profile];

 

for(profile p : ps){
     if(p.PermissionsViewAllData==true){
           list<user> users = p.users;
            if(us.size()!=0){}//do something with list          

      }

}