How to assign custom permission in salesforce?
How can we assign custom permission to users via apex coding?
Custom Permission in salesforce cannot be assigned to the user directly. That could be done by means of assigning the Permission Set to the user. Custom Permission should already be assigned to the Permission Set :
PermissionSetAssignment assignment = new PermissionSetAssignment(); assignment.AssigneeId = userId; assignment.PermissionSetId= permissionSetId; insert assignment;
or assigning Custom Permission to the profile.
Assigning Custom Permission to a Profile or Permission Set can be done via salesforce UI, or via Metadata API.
Take a look at Enable Custom Permissions in Permission Sets and Enable Custom Permissions in Profiles