Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Assign Custom permission to profile using Apex

Are there any solutions that allow assigning Custom permission to Profiles using apex? I know about the object SetupEntityAccess . But it is for linking Custom Permission and Permission Set. But I want to avoid using the Permission Set

  • custom-permission

Derek F's user avatar

  • 2 IMHO you really need to embrace Permission Sets and Permission Set Groups; Salesforce is on a journey to deprecate Profiles so the sooner you switch the sooner you get that transition out of the way, before you implement additional things like this that will make the transition harder for you. –  Phil W Jan 5 at 8:11

2 Answers 2

Hope you are doing well, using Apex you can assign permission set to any user. Only we need that permission set 'Id' and the 'Id' of the User to be assigned.

/* Get the Id of the permission Set using Permission Set Name */

/* Now you need to assign that permission set to the user, So first get the User using SOQL*/

I hope you got you answer, if not feel free to ask.

Aryan Sharma's user avatar

  • 1 This doesn't really answer the original question which stated they wanted to avoid permission sets. Additionally the existing answer already covers permission set assignments that are more aligned to the original question than this so I can't upvote what you have here. –  Phil W Jan 5 at 12:23
  • Custom Permission cannot be assigned to the user directly. That could be done by means of assigning Permission Set to the user. Custom Permission should already be assigned to the Permission Set 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 :… and… –  Aryan Sharma Jan 5 at 12:30
  • 1 You misunderstand me; the other answer already covers permission set usage (and I am aware of what can and cannot be done with custom permission assignment and Apex). I don't understand why you added this answer when the other answer already covers assigning a permission set (with the custom permission) to all users with a given profile. –  Phil W Jan 5 at 12:36
  • Thanks for your answers. But @PhilW is right. The original question was about how to avoid permission-set usage. We can do this manually. I mean edit Profile and add Custom Permission. I guess the solution via apex that I need doesn't exist –  Vadym Jan 5 at 22:57

I have a solution which will help you out.

Via Metadata Api using the library from FinancialForce, you can get it at - All you need to do is copy the MetadataService class and save it into your org.

once done add the below method to your Apex class-

Mukul Mahawariya's user avatar

  • Doesn't quite answer the question, though what you provided is valuable. Could you edit the answer to give a bit more info as to why you would take this approach, not just show the code? –  Phil W Jan 5 at 8:13
  • What you can do is create a permission set which has the custom permissions that you want to give to a user. And by following the above code you can just assign the permission set to the user which will give them the desired access. –  Mukul Mahawariya Jan 5 at 10:07
  • Please edit the answer to provide these details. –  Phil W Jan 5 at 12:21
  • @Vadym Please go through the updated answer. –  Mukul Mahawariya Jan 9 at 9:37
  • Never just add the MetadataService class; make sure to also add the related unit tests to keep your code coverage up. –  Phil W Jan 9 at 10:03

You must log in to answer this question.

Not the answer you're looking for browse other questions tagged apex custom-permission ..

  • The Overflow Blog
  • What it’s like being a professional workplace bestie (Ep. 603)
  • Featured on Meta
  • Moderation strike: Results of negotiations
  • Our Design Vision for Stack Overflow and the Stack Exchange network

Hot Network Questions

  • Two ideal ohmmeters in parallel
  • Vita Bene Vixit in a commemorative magazine
  • Why quantum entanglement for a non-local object needs explanation?
  • Coworker hiding and stealing lab material
  • According to an online course, ribose and adenine can bond to make ATP. Is this true?
  • Has anyone been charged with a crime committed in space?
  • Does Bayesianism give an out for pseudoscience that it shouldn’t deserve?
  • Is this Linear Logic Prover Wrong?
  • How to terminate a soil drain pipe into the earth and avoid blockages
  • What is important to keep in mind in grading proof-based courses?
  • polynomials and dimensions
  • How to properly define volume for beginner calculus students?
  • What does the clown mean by saying that brothels in the cities "shall stand for seed" in the second scene of "Measure for Measure"?
  • Did Einstein say "Do not worry about your difficulties in mathematics, I assure you that mine are greater"?
  • How to slow down while maintaining altitude
  • How to know which areas of a new song to sing softly and which areas to sing loudly?
  • is it possible to turn this dumb-waiter into an elevator?
  • Unexpected tangency
  • Why do people say 'topless' but not 'topful'?
  • Voltage Tolerance for Power Supplies
  • Short story about an engineer coming back to an abandoned city where only the robots are working. I read it in an anthology in the 1970's
  • Is the liquid inside the canned chickpeas meant for consumption?
  • Correcting how a student writes symbols
  • Understanding Limit points.

assign custom permission to profile salesforce

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy .

Are you ready for the Salesforce Winter '24 Release?

Check out the full list of new features and updates available in the Winter ’24 Release.


Did you find this helpful?

Help us enhance your experience.

banner footer image

User capabilities with 'Customize Application' Profile permission

  • Customize the Organization Using App Setup Menu Options
  • Edit Messages and Custom Links
  • Modify Standard Picklist Values
  • Create, Edit, and Delete Custom Fields
  • Note: This permission also requires the 'Edit' permission for the object, for example, 'Edit' on Accounts
  • Set Field-Level Security
  • Create, Edit, and Delete Custom Links
  • Edit the Lead Settings
  • Activate Big Deal Alerts
  • Create Record Types
  • Set Up Web-to-Case and Email Response Rules
  • Set Up Web-to-Lead and Email Response Rules
  • Set UP Assignment and Escalation Rules
  • Set Up Business Hours;
  • Set Up Email-to-Case or On-Demand Email-to-Case
  • Note: This permission also requires the 'Manage Self-Service Portal' permission to set up and maintain Self-Service settings and delete your organization's Self-Closed Case Status value.
  • Set Up and Enable Multilingual Solutions
  • Set Up Team Selling
  • Set Up Account Teams
  • Map Custom Lead Fields
  • Manage Queues
  • Create, Edit, and Delete Workflow Rules, Tasks, Field Updates, Outbound Messages, and Alerts
  • Create, Edit, and Delete Custom S-Controls, Custom objects, and Custom Tabs
  • Rename Tabs
  • Manage Custom Apps and Service Cloud Console Apps
  • Create and Edit Public Calendars and Resources
  • Set Up the Console
  • Enable, Set Up, and Modify the Salesforce Customer Portal
  • Set Up and Schedule Analytic Snapshots to Run
  • Create Communities for Ideas and Answers
  • Create Visualforce Email Templates
  • Enable Advanced Currency Management and Change Currencies
  • View and set List API Name when creating List View" after Enable Advanced Currency Management and Change Currencies
  • Clone Profiles

Company Logo

Cookie Consent Manager

General information, required cookies, functional cookies, advertising cookies.

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings. Privacy Statement

Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.

Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.

Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.

Cookie List


  1. Custom permissions in Salesforce

    assign custom permission to profile salesforce

  2. How to use Custom Permission in Salesforce Validation Rule

    assign custom permission to profile salesforce

  3. Profile and Permission Set Helper (Update)

    assign custom permission to profile salesforce

  4. Custom Permissions in Salesforce

    assign custom permission to profile salesforce

  5. Replace Profile IDs with Custom Permissions in Validation Rules

    assign custom permission to profile salesforce

  6. Difference between Profiles and Permission Sets in Salesforce

    assign custom permission to profile salesforce


  1. Custom Application using Salesforce com-First Part

  2. Salesforce Developer Türkçe

  3. Salesforce Profile Sales cloud

  4. salesforce user roles

  5. Why Salesforce Custom Development For Integration?

  6. How to switch to Enhanced Profile User Interface of Salesforce


  1. Enable Custom Permissions in Profiles

    Install the User Access and Permissions Assistant. Create a Named Credential for the Tooling API. Permission Set Groups Considerations. Edit Object Permissions in Profiles. Create a Permission Set with Required Permissions for the User... Permission Set Groups. Permission Set Groups and Combined Permissions View.

  2. Custom Permissions

    Remote Access Application Secure Identity for the Internet of Things Using and Validating Asset Tokens Proof-of-Possession for Asset Tokens Prerequisites for Implementing Asset Tokens Setting Apex Class Access from Permission Sets Setting Visualforce Page Security from Permission Sets View and Edit Visualforce Pages Manage Visualforce Pages

  3. Assign Custom permission to profile using Apex

    List<PermissionSetAssignment> permissionSetList = new List<PermissionSetAssignment> (); for (User u : [SELECT Id, UserRole.Name,Profile.Name, IsActive FROM User WHERE UserRole.Name LIKE '%UserRoleName%' AND Profile.Name Like '%UserProfileName%' AND IsActive = true]) { PermissionSetAssignment psa = new PermissionSetAssignment (PermissionSetId = ...

  4. Custom Permissions

    Use custom permissions to give users access to custom processes or apps. ... Account. Access Trailhead, your Trailblazer profile, community, learning, original series ...

  5. User capabilities with 'Customize Application' Profile permission

    'Customize Application' is a powerful administrative permission. Administrators should be aware of the capabilities granted to users who are given the 'Customize Application' permission, as outlined below. Available in: Enterprise , Performance , Unlimited , Developer, editions