You want this result from Apex code or from native screens?
If native screen then Setup > Administrator Setup > Manage Users > Profile > Click on your profile > Click on Assigned users.
If you want this from Apex code then here it is : (Code is not best optimized as it is created in 10 mins :) )
List<User> uList = [select id,ProfileId from User] ;
List<Profile> pList = [select id,name from profile] ;
List<Profile> profileWithNoUser = new List<Profile>() ;
for(Profile p : pList)
{
boolean flag = false ;
for(User u : uList)
{
if(u.ProfileId == p.Id)
{
flag = true ;
}
}
if(!flag)
{
profileWithNoUser.add(p) ;
}
}
System.debug('profileWithNoUser ::: ' + profileWithNoUser + ' ::: ' + profileWithNoUser.size() ) ;
Now role hierarchy : Please visit my latest blog post where on visualforce page I have displayed all users falling under each role. Unmanaged package is also there, so you have the code too :)
You want this result from Apex code or from native screens?
If native screen then Setup > Administrator Setup > Manage Users > Profile > Click on your profile > Click on Assigned users.
If you want this from Apex code then here it is : (Code is not best optimized as it is created in 10 mins :) )
List<User> uList = [select id,ProfileId from User] ;
List<Profile> pList = [select id,name from profile] ;
List<Profile> profileWithNoUser = new List<Profile>() ;
for(Profile p : pList)
{
boolean flag = false ;
for(User u : uList)
{
if(u.ProfileId == p.Id)
{
flag = true ;
}
}
if(!flag)
{
profileWithNoUser.add(p) ;
}
}
System.debug('profileWithNoUser ::: ' + profileWithNoUser + ' ::: ' + profileWithNoUser.size() ) ;
Now role hierarchy : Please visit my latest blog post where on visualforce page I have displayed all users falling under each role. Unmanaged package is also there, so you have the code too :)
Select report type as Users< from Administrative Reports>-->choose format as Summary--> First group by Role --> Then sub-group by Active flag.--> Run Report and Click Hide Details.
User-Profile summary report:
Select report type as Users< from Administrative Reports>--> choose format as Summary--> First group by Profile --> Then sub-group by Active flag.--> Run Report and Click Hide Details.
You want this result from Apex code or from native screens?
If native screen then Setup > Administrator Setup > Manage Users > Profile > Click on your profile > Click on Assigned users.
If you want this from Apex code then here it is : (Code is not best optimized as it is created in 10 mins :) )
Now role hierarchy : Please visit my latest blog post where on visualforce page I have displayed all users falling under each role. Unmanaged package is also there, so you have the code too :)
http://forceguru.blogspot.com/2011/12/displaying-role-hierarchy-on.html
And here is the working demo : http://treeview-developer-edition.ap1.force.com/
Thanks
Ankit Arora
Blog | Facebook | Blog Page
All Answers
You want this result from Apex code or from native screens?
If native screen then Setup > Administrator Setup > Manage Users > Profile > Click on your profile > Click on Assigned users.
If you want this from Apex code then here it is : (Code is not best optimized as it is created in 10 mins :) )
Now role hierarchy : Please visit my latest blog post where on visualforce page I have displayed all users falling under each role. Unmanaged package is also there, so you have the code too :)
http://forceguru.blogspot.com/2011/12/displaying-role-hierarchy-on.html
And here is the working demo : http://treeview-developer-edition.ap1.force.com/
Thanks
Ankit Arora
Blog | Facebook | Blog Page
Hi Ankit,
Thank you for your reply.
Having more than 50 roles and profiles. I would like an easy way (report) saying how many users are assigned to each role/profile.
Currently I have to do it in the native way you mentioned: Profile > Click on your profile > Click on Assigned users, for each of the profiles.
Would be perfect to see in a glance if I have roles and profiles that can be deleted!
Thank you for your help!!!!
Your code works for the role hieratchy!! what about the Profiles?
:))
You can run 'Summary' reports on User object.
User-Role summary report:
Select report type as Users< from Administrative Reports>-->choose format as Summary--> First group by Role --> Then sub-group by Active flag.--> Run Report and Click Hide Details.
User-Profile summary report:
Select report type as Users< from Administrative Reports>--> choose format as Summary--> First group by Profile --> Then sub-group by Active flag.--> Run Report and Click Hide Details.