salesforceapexsalesforce-lightning

Quickest way to see if user has a perm set with modify all on the object in question


I think I could do this with a bunch of queries, but don't want to hit limits. I have an LWC where I need to programmatically show a button based on the user's ability to update the record. I've got all other methods accounted for. I have the record id of the object as input. Apparently the UserRecordAccess object is not providing the correct answer here.


Solution

  • You don't need the record's id, if you have "Modify All" it'll be regardless?

    Something like this? Just plug UserInfo.getUserId().

    SELECT Id, Name, Profile.Name
    FROM PermissionSet
    WHERE Id IN (SELECT PermissionSetId FROM PermissionSetAssignment WHERE AssigneeId = '005...')
    AND Id IN (SELECT ParentId FROM ObjectPermissions WHERE SobjectType = 'Case' AND PermissionsModifyAllRecords = true)
    LIMIT 1
    

    Should find it whether it's a real permset or a hidden one 1:1 linked to profile.