I want to modify CRUD permissions for a custom object inside my Visualforce page controller (accessible only by administrators) in order to hide/show this object to other users when clicking on a button.

My goal is to avoid losing time doing it manually especially if there are lots of profiles.

Is there an easy way to do this ?

I know how to check for permissions, but not how to modify them :

if (Schema.sObjectType.MyObject.isAccessible())


Thanks for your answers.

1 Answer 1


I know this doesn't directly answer your question but your best solution would be to use Permission sets (see here) and use the standard Salesforce admin UI to assign to the correct users. If you create a permission set for each of the CRUD permissions would may want to assign then the admin will just need to assign as and when necessary.

  • Thanks Richard, it could be a solution, but the problem is that permission sets cannot be assigned to profiles, but to users.
    – arnaud
    Dec 1, 2015 at 10:40
  • You can create you VF page to look for users that match the profile you want to administer and apply the permission set in Apex. See developer.salesforce.com/docs/atlas.en-us.api.meta/api/… for the PermissionSetAssignment object Dec 1, 2015 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.