Query CRED And FLS Permissions - Examples

Query All Permissions

To get a list of every CRED setting for every Profile and Permission Set in Salesforce run the following query, or use Data Loader to export all ObjectPermissions records with the following fields:

SELECT Id, ParentId, Parent.ProfileId, Parent.Profile.Name, SobjectType, PermissionsCreate, PermissionsDelete, PermissionsEdit, PermissionsRead, PermissionsViewAllRecords, PermissionsModifyAllRecords
FROM ObjectPermissions

To query all Field permissions use a similar query:

SELECT Id, ParentId, Parent.ProfileId, Parent.Profile.Name, SobjectType, Field, PermissionsEdit, PermissionsRead
FROM FieldPermissions

In order to limit your search to specific profiles, add a filter to the end using the Parent.ProfileId field . Example:

SELECT Id, (...)
FROM (...)
WHERE Parent.Profile.Name = 'Sales Manager'

Or if you have a list of profiles:

SELECT Id, (...)
FROM (...)
WHERE Parent.Profile.Name IN ('Sales Manager', 'Sales', 'Marketing')

To limit your query to only see permissions related to Profiles and not Permission Sets, add a filter to the end using the Parent.ProfileId field to make sure it’s not empty:

SELECT Id, (...)
FROM (...)
WHERE Parent.ProfileId != null

Conversely, to limit your query to only show permissions related to Permission Sets, adjust the filter:

WHERE Parent.ProfileId = null

In order to limit the Objects you want permissions for, add a filter to the end using the SobjectType field. Example:

SELECT Id, (...)
FROM (...)
WHERE SobjectType IN ('Account','Opportunity','Contact')
Query Permissions For Specific Fields

In order to limit the Fields you want permissions for, add a filter to the end using the Field field. Note that the values in the Field field include API name of the Object, followed by a period, then the API name of the Field. Example:

SELECT Id, (...)
FROM (...)
WHERE Field IN ('Account.Customer__c','Opportunity.Total__c','Contact.LastName')