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
jaishrijaishri 

I want to query all profiles, permission set with users and also want to count each profile how many users what permission set they assigned . Can anyone help me

SELECT  PermissionSet.Profile.Name , PermissionSet.Name ,AssigneeId , Assignee.Name FROM PermissionSetAssignment GROUP BY  PermissionSet.Profile.Name ORDER BY PermissionSet.Profile.Name ASC
AnkaiahAnkaiah (Salesforce Developers) 
Hi Jaishri,

You can't able to get all in single query.

count of users for each profile use the below query.
SELECT count(Id), Profile.Name FROM User GROUP BY Profile.Name
try with below query for count of users assigned to permissionset.
Set<id> permissionsetids = new set<id>();

for(PermissionSet psa:[select id,Name from PermissionSet]){
permissionsetids.add(psa.id);
}

AggregateResult ar = [SELECT count(AssigneeId), PermissionSetId FROM PermissionSetAssignment GROUP BY PermissionSetId WHERE PermissionSetId IN:permissionsetids];

If this helps, Please mark it as best answer.

Thanks!!
 
aslam khan 27aslam khan 27
Myasiantv (https://myasiantv.fan/) You can watch Online free releases in Korean Dramas, Taiwanese, Hong Kong, Thailand and Chinese with English Sub In High Quality.