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
Bryan Leaman 6Bryan Leaman 6 

How can I check for Modify All Data permission in Apex?

I love how we can filter lightning components on standard permissions rather than looking for specific profile name or creating custom permissions. For example, instead of someting like  Profile > Name = 'System Administrator' I can show a component based on "Permissions > Standard Permissions > Modify All Data = true".

But I'm unable to find a way to make this same kind of determination in Apex. My use-case is that I'd like to condition editability of some data based on the status of the record *AND* whether the user has been granted a custom permission *or* they are a system admin (so I don't have to keep adding all custom permissions to our system administrators). But I've been unable to find a way to check for "Modify All Data" authority on the running user.
Best Answer chosen by Bryan Leaman 6
AnkaiahAnkaiah (Salesforce Developers) 
Hi Bryan,

Similar kind of question answered here.

https://salesforce.stackexchange.com/questions/44237/how-can-we-access-modify-all-data-setting-from-profile-in-apex

If the above information helps, Please mark it as best answer.

Thanks!!

 

All Answers

AnkaiahAnkaiah (Salesforce Developers) 
Hi Bryan,

Similar kind of question answered here.

https://salesforce.stackexchange.com/questions/44237/how-can-we-access-modify-all-data-setting-from-profile-in-apex

If the above information helps, Please mark it as best answer.

Thanks!!

 
This was selected as the best answer
Bryan Leaman 6Bryan Leaman 6
Thanks. So putting it together, I can tell if the current running user has ModifyAllData like this:
List<PermissionSetAssignment> modifyAllDataPSAs = [
    SELECT AssigneeId 
    FROM PermissionSetAssignment 
    WHERE PermissionSet.PermissionsModifyAllData=true
          AND AssigneeId=:UserInfo.getUserId()
];
boolean hasModifyAllData = modifyAllDataPSAs.size()>0;