Skip to main content

Custom Permission in Salesforce

 

💬 In plain words:  A Custom Permission is a simple yes/no flag you attach to users, which your code and flows can check — like a feature switch per person. Use it instead of hardcoding profile names in logic.

📌 Example:  Validation rule blocks editing closed Cases — but the audit team must edit them. Create Custom Permission 'Edit_Closed_Cases', add NOT($Permission.Edit_Closed_Cases) to the rule, assign it to auditors via a permission set. No profile checks in formulas.

🎬 Real-Life Example: Bypassing a Validation Rule  Imagine you have a rule: no one can discount an Opportunity by more than 20%. But the VP of Sales needs to override this rule when closing major deals.

The Old/Bad Way (hardcoding):  You write a validation rule that checks the user's profile name: Discount__c > 0.20 && $Profile.Name != 'System Administrator' && $Profile.Name != 'VP of Sales'.

Why this is bad:  If you later decide that Regional Managers should also get this power, you must rewrite the formula. If a user changes roles, you must update their profile. It becomes a maintenance nightmare.

The New/Good Way (Custom Permissions):  1. Create a Custom Permission named Can_Approve_Large_Discounts.  2. Create a Permission Set called "Discount Approvers" and add that Custom Permission to it.  3. Assign the Permission Set to the VP of Sales — and anyone else who needs it.  4. Write the rule to look for the pass, not the person: Discount__c > 0.20 && NOT($Permission.Can_Approve_Large_Discounts).

The payoff:  The system no longer cares who the user is or what profile they have. It only checks if they hold the "VIP pass". A new manager needs the power? Assign the Permission Set. Done.

Concept

A Custom Permission is a named flag that you define, assign, and check. You can check it in Apex, in formulas, in validation rules and in flows. That decouples 'can this user do X' from checks on profile name or role. You assign it through permission sets and PSGs, covered in 1.2. You check it with $Permission.MyPerm in declarative places, and with FeatureManagement.checkPermission('MyPerm') in Apex. It is the maintainable answer to 'only certain users can override this rule'. Hardcoding profile names is brittle. Gating on a custom permission is portable and auditable. Custom Permissions are often bundled with Connected Apps, or shipped with a feature.

🧠 Custom Permission = named flag you CHECK, not a profile-name hardcode. $Permission.X (formula/VR/flow) · FeatureManagement.checkPermission('X') (Apex). Assign via permission set. 

Core Q&A

Q: You need a validation rule that everyone must pass EXCEPT a small group of override users. How do you implement it maintainably?

🎯 Say this first:  Create a Custom Permission. Check it in the validation rule with $Permission. Assign it to the override group through a permission set.

A: Define a Custom Permission — call it 'Bypass_Amount_Limit'. Assign it through a permission set to the users who may override. Then write the validation rule so it fires only when NOT $Permission.Bypass_Amount_Limit. Common mistake: hardcoding profile names in the rule. That breaks the moment a profile is renamed or cloned, and it forces a rule edit every time the org grows. The permission travels across profiles, and it audits cleanly — whoever holds the permission set holds the permission. The same flag also gates Apex, through FeatureManagement.checkPermission, and gates flows, so all three stay consistent. Adding or removing an override user is one permission-set assignment and zero rule edits.

// Validation Rule formula:

//   AND( Amount__c > 10000, NOT($Permission.Bypass_Amount_Limit) )

 

// Apex check:

if (FeatureManagement.checkPermission('Bypass_Amount_Limit')) {

    // allow the privileged path

}

Follow-ups (scenario-based)

Q1: Custom Permission vs a checkbox on a Custom Setting vs checking the profile name — when each?

A1: Use a Custom Permission to gate a capability per user. You assign it with permission sets, and you can check it in code and in declarative tools. That is the default answer to 'which users can do X'. Use a Hierarchy Custom Setting checkbox when the override carries a value, and you need it at user, profile or org level. Bypass switches are the classic case: 'skip automation for this integration user'. It works in Apex and in validation rules through $Setup — see 2.3. Checking the profile NAME: almost never. It breaks on rename and on clone, and it does not travel. Simple rule: a capability is a Custom Permission, a configuration value or a bypass is a Custom Setting, and profile names are never hardcoded.

Q2: How do Custom Permissions help package or feature-gate functionality?

A2: A Custom Permission gives you a clean on/off gate that does not care who the user is. The feature's code and its automation check the permission. Turning the feature on for a user or an org is just an assignment, through a permission set that can ship inside a package. That buys you three things. You can deploy code dark — present, but gated off. You can roll out to a pilot group by assigning the permission. And you can gate premium features in a managed package, because Custom Permissions can be packaged and tied to Permission Set Licenses. The pattern in one line: ship the capability, gate it with a Custom Permission, control rollout by assignment. No code change turns a feature on.

Q (compare): If we can assign a permission set, why do custom permissions exist at all?

A: The permission set GRANTS access. The custom permission is a FLAG inside it that your own logic can TEST. A validation rule or Flow cannot ask 'does this user hold permission set X?'. But it can check a custom permission in one line. It also keeps logic and packaging separate. The flag can move to another permission set without touching the rule. Skyline: 'Override_Delivery_Price' is a custom permission checked by a validation rule. Managers get it through their permission set.

Popular Posts

Apex Test Class Examples for @HttpPost Exposed WebService Class

Introduction: In Salesforce, the Apex programming language allows you to create powerful web services that can be exposed to external systems for data integration. One common scenario is using the @HttpPost annotation to create a custom RESTful web service. In this blog post, we'll walk through some examples of how to write effective test classes for an @HttpPost exposed web service class in Salesforce. Writing comprehensive test classes ensures that your code is robust, functional, and ready for deployment.

Must-listen songs for developers

Here are some must-listen songs for developers: "Strobe" by deadmau5 . This electronic dance music (EDM) track is perfect for getting into a flow state. The repetitive beat and simple melody are easy to focus on, and the overall mood of the song is upbeat and motivating.  "Viva la Vida" by Coldplay . This rock song has a soaring melody and powerful lyrics that can inspire you to stay focused and productive. The song's message of hope and resilience is perfect for those times when you're feeling stuck or discouraged.  "Code Monkey" by Jonathan Coulton . This tongue-in-cheek song is a hilarious and accurate portrayal of the life of a software developer. The lyrics are catchy and the song's upbeat tempo will make you want to get up and dance.  "The Sound of Silence" by Simon & Garfunkel . This classic folk song is perfect for those times when you need to focus and concentrate. The song's slow tempo and haunting melody will h...

Uninstall all Windows 10 default apps using Powershell

Here is script to uninstall all windows 10 default modern apps. This script uninstalls xbox, xbox Game bar, Xbox App,Xbox Gaming Overlay, Get started etc from your computer. No need to run one by one commands Just copy below script, run  powershell as administrator and paste script and press enter . It will automatically uninstall all default programs.  If you do not  want to uninstall some apps than just remove " "  line from script. $packages = @( "7EE7776C.LinkedInforWindows" "C27EB4BA.DropboxOEM" "Microsoft.3DBuilder" "Microsoft.Microsoft3DViewer"

Salesforce LWC Code for Multi-Select Lookup

Introduction: In Salesforce Lightning Web Components (LWC), implementing a multi-select lookup field can enhance the user experience and provide greater flexibility for selecting multiple related records. In this blog post, we will walk through the process of creating a multi-select lookup field using LWC. We will cover the required code snippets and provide step-by-step instructions to help you implement this functionality in your Salesforce org.

How to Save Quote PDF, Send PDF, Preview PDF in salesforce with custom functionality

Want to develop custom pdf viewer, save pdf in quote pdf related List and Send quote to customer on button click when quote is custom in salesforce . These functionality are standard from salesforce. but you can develop these functionality custom in salesforce. Here is the solution:- Custom button to save Quote PDF and send PDF  Step 1:-  First Create Two custom button. which will used for PDF preview and Save quote pdf in quotes pdf related list.                               1. PDF preview Button                              2. Save & Send Quote Button Replace "Your VF page here" to Your quote PDF cuatom page. Step 2:-  PDF preview button   pdf preview button will display the pdf's preview in standard format of salesforce. So you need to set the  following configuration (In picture). After that you have ...

Unveiling the Power of Named Credentials in Salesforce with Comprehensive Code Examples

Introduction: Named Credentials are a powerful feature in Salesforce that allow you to securely authenticate and connect to external services and APIs without exposing sensitive information like usernames and passwords. In this blog post, we'll delve into the world of Named Credentials, understand their significance, and provide you with in-depth code examples to illustrate their implementation in various scenarios.

Setup vs Non-Setup Objects (Mixed DML)

Core Platform & Fundamentals Module map MODULE 1 root: 'Who can do what, on which objects/fields?' ├─ Setup vs non-setup (transaction rules) ├─ Profile + Perm Sets + PSG (access = union) ├─ Licensing (the ceiling) ├─ CRUD/FLS (objects & fields) └─ Reports/Dashboards (who sees what data) 1.1 Setup vs Non-Setup Objects (Mixed DML) 💬 In plain words:   Salesforce keeps 'admin' records (like User, Group) and 'business' records (like Account, Case) in two separate rooms. One transaction cannot write to both rooms at once — that error is Mixed DML. The fix: do the second write in a separate async step. Concept