Skip to content

PranavNagrecha/AwesomeSalesforceSkills / skills/admin/custom-permissions

custom-permissions

Verified

Use when creating, assigning, or checking custom permissions to control feature access beyond CRUD and FLS. Trigger keywords: 'custom permission', 'FeatureManagement.checkPermission', '$Permission global variable', 'feature gate', 'named access grant', 'beta feature flag', 'SetupEntityAccess', 'requiredPermission', 'who has this custom permission'. NOT for gating Apex service code and its tests — use apex/apex-custom-permissions-check. NOT for permission set design — use admin/permission-set-architecture.

templates/custom-permissions-template.md

View on GitHub
# Custom Permissions — Work Template

Use this template when working on a custom permissions task. Fill in each section before starting implementation.

---

## Scope

**Skill:** `custom-permissions`

**Request summary:** (describe what the user asked for — what feature needs to be gated, or what access check needs to be added)

---

## Context Gathered

Answer these before writing any metadata or code:

- **Custom permission API name:** (must start with a letter; alphanumeric + underscore only)
- **Custom permission label:** (human-readable; appears in permission set editor)
- **Platform contexts that will check the permission:**
  - [ ] Apex (`FeatureManagement.checkPermission`)
  - [ ] Validation rule (`NOT($Permission.X)` in AND condition)
  - [ ] Formula field (`$Permission.X`)
  - [ ] Flow (formula resource of type Boolean)
  - [ ] Visualforce (`{!$Permission.X}`)
  - [ ] LWC (`@salesforce/customPermission/X`)
  - [ ] Lightning page component visibility / Dynamic Forms (`{!$Permission.CustomPermission.X}`)
  - [ ] In-App Guidance `uiFormulaRule`
- **Description text (names every consumer above; 255-char limit):**
- **Does another custom permission have to be enabled with this one (`requiredPermission`)?**
- **Is the grant permanent, or does it expire?** (see `admin/permission-set-expiration`)
- **Permission sets that will carry this permission:** (list all)
- **Users or personas who should receive the permission:** (list or describe)
- **Is this a new permission or modifying an existing one?**

---

## Approach

Which pattern from SKILL.md applies?

- [ ] Feature Gate for Beta or Graduated Rollout
- [ ] Admin-Only Bypass in Validation Rules
- [ ] Conditional UI Visibility Gate in LWC
- [ ] Other: _______________

Why this pattern:

---

## Metadata Checklist

- [ ] Custom permission created in Setup (or `customPermissions/*.customPermission-meta.xml` authored)
- [ ] Permission set XML updated with `<customPermissions>` node
- [ ] All permission sets that need this permission have been updated
- [ ] Metadata committed to source control

## Apex / Formula Checklist

- [ ] `FeatureManagement.checkPermission('API_Name')` used in all Apex guards
- [ ] `$Permission.API_Name` used in all formula/validation rule references
- [ ] Apex unit tests have permission set assignment in `@TestSetup`
- [ ] Both positive (has permission) and negative (no permission) test cases exist
- [ ] `System.runAs(testUser)` wraps the code-under-test in permission-gated test methods

## Flow Checklist

- [ ] Formula resource of type Boolean created with value `$Permission.API_Name`
- [ ] Decision element conditions reference the formula resource variable, not the raw `$Permission` syntax

---

## Deployment Checklist

- [ ] Custom permission metadata included in deployment package
- [ ] All dependent permission sets included in deployment package
- [ ] Apex classes with updated guards included
- [ ] Validation rule updates included
- [ ] `check_custom_permissions.py` run on the post-deploy metadata to confirm assignments

---

## Notes

Record any deviations from the standard pattern and why:

---

## Reference Syntax

| Context | Syntax |
|---|---|
| Apex | `FeatureManagement.checkPermission('My_Custom_Permission')` |
| Validation rule bypass | `AND(NOT($Permission.My_Custom_Permission), /* rule conditions */)` |
| Formula field | `$Permission.My_Custom_Permission` |
| Flow formula resource | `$Permission.My_Custom_Permission` (used as resource value, type Boolean) |
| Visualforce | `{!$Permission.My_Custom_Permission}` |
| LWC | `import hasPerm from '@salesforce/customPermission/My_Custom_Permission';` (resolves to `true` or `undefined`) |
| Component visibility / In-App Guidance | `{!$Permission.CustomPermission.My_Custom_Permission}` — note the extra `CustomPermission.` segment |
| Permission set XML | `<customPermissions><enabled>true</enabled><name>My_Custom_Permission</name></customPermissions>`, inside a `<PermissionSet>` root |

Full deployable files, package.xml, deploy order, and the `SetupEntityAccess` verification queries are in `references/metadata-examples.md`.
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 323kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 323kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 323kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall