How to assign custom permission in salesforce?

235    Asked by ClareMatthews in Salesforce , Asked on Jun 5, 2023

 How can we assign custom permission to users via apex coding?

Answered by Clare Matthews

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

Your Answer

Interviews

Parent Categories