Skip to content

Instantly share code, notes, and snippets.

@ADelRosarioH
Last active January 12, 2017 18:41
Show Gist options
  • Save ADelRosarioH/af38336bfe34b3ba5424819c43a3c0ad to your computer and use it in GitHub Desktop.
Save ADelRosarioH/af38336bfe34b3ba5424819c43a3c0ad to your computer and use it in GitHub Desktop.
Select all profiles that have access to an sobject in salesforce
List<ObjectPermissions> permissionSetAssignmentIds = [SELECT ParentId
FROM ObjectPermissions
WHERE
PermissionsCreate = True AND
PermissionsRead = True AND
PermissionsEdit = True AND
PermissionsDelete = False AND
PermissionsViewAllRecords = False AND
PermissionsModifyAllRecords = False AND
sObjectType = 'Opportunity'];
Set<Id> permissionsSetAssignmentsIdsSet = new Set<Id>();
for(ObjectPermissions op : permissionSetAssignmentIds){
permissionsSetAssignmentsIdsSet.add(op.ParentId);
}
List<PermissionSetAssignment> permissionSetIds = [SELECT PermissionSetId FROM PermissionSetAssignment WHERE PermissionSetId IN :permissionsSetAssignmentsIdsSet];
Set<Id> permissionsSetIdsSet = new Set<Id>();
for(PermissionSetAssignment ps : permissionSetIds){
permissionsSetIdsSet.add(ps.PermissionSetId);
}
List<PermissionSet> profileIds = [SELECT ProfileId FROM PermissionSet WHERE Id IN :permissionsSetIdsSet];
Set<Id> profileIdsSet = new Set<Id>();
for(PermissionSet p : profileIds){
profileIdsSet.add(p.ProfileId);
}
List<Profile> profiles = [SELECT Id, Name FROM Profile WHERE Id IN :profileIdsSet];
for(profile p : profiles){
system.debug(p.name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment