Custom Permissions 标志

Custom Permissions

社区
PranavNagrecha
custom-permissions

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.

概览

发布者PranavNagrecha
代码仓库AwesomeSalesforceSkills
技能名称custom-permissions
星标数
26
复刻数
5
附带文件
7
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 7 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 PranavNagrecha 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Custom Permissions AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/PranavNagrecha/AwesomeSalesforceSkills/tree/main/skills/admin/custom-permissions
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/PranavNagrecha/AwesomeSalesforceSkills.git /tmp/AwesomeSalesforceSkills
mkdir -p .claude/skills
cp -r /tmp/AwesomeSalesforceSkills/skills/admin/custom-permissions .claude/skills/custom-permissions
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Custom Permissions,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Custom Permissions。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Custom Permissions 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Custom Permissions

Use this skill when a feature or capability needs a named access gate that goes beyond object, field, or record permissions. Custom permissions grant boolean access to a named capability and can be checked in validation rules, formula fields, Apex, Flow, LWC, Visualforce, and Lightning page component visibility. Each of those contexts spells the check differently.


Before Starting

  • Confirm you need a custom permission, not a permission set feature license or a record-level sharing rule. Custom permissions are for feature on/off gates, not record visibility.
  • Identify all platform contexts that must check the permission (validation rule, formula, Apex, Flow). Each uses a different syntax.
  • Gather the exact API name you want. DeveloperName must begin with a letter, contain only alphanumerics and underscores, not include spaces, not end with an underscore, and not contain two consecutive underscores; limit 80 characters (Object Reference, CustomPermission.DeveloperName). The name cannot be changed after creation without updating every reference.
  • Determine which permission sets will carry the permission. A Profile can also carry one — Profile.customPermissions exists in the Metadata API from version 31.0 — but a profile-borne grant is invisible in the Custom Permissions related list, so grant through a permission set (references/gotchas.md Gotcha 1).

Questions to Ask Before Configuring

Ask these before creating anything. A custom permission is trivial to create and permanent in practice, so the cost of a wrong answer is paid later, by whoever inherits the org.

AskWhy it mattersWhat a good answer adds
"What exactly does holding this permission let someone do, in one sentence?"If the sentence needs an "and", this is two permissions; a single flag that means several things cannot be revoked partiallyThe permission's description, and possibly a second permission
"Which contexts read it — validation rule, formula, Flow, Apex, LWC, component visibility?"Each has a different spelling, and component visibility needs the extra CustomPermission. segmentThe consumer list, and the set of syntaxes to get right (Gotcha 6)
"Does anything already hold this access through a profile?"Profile.customPermissions deploys cleanly and hides in the profile-owned permission setA SetupEntityAccess baseline before you add a second grant path (Gotcha 1)
"Does another custom permission have to be on for this one to make sense?"requiredPermission enforces that at the platform level instead of in proseA CustomPermissionDependencyRequired node and a single-package deploy order
"Who revokes it, and what proves it was revoked?"A metadata diff cannot prove revocation — only enabled grants are ever retrievedAn owner and a live SetupEntityAccess query as the evidence artifact (Gotcha 8)
"Is this a bypass? If so, which named rules does it suppress?"An unnamed bypass becomes an org-wide off switch nobody dares removeThe rule list in the description and a scoped Bypass_Validation_<Domain> name
"Is the grant permanent, or should it expire?"Data-fix and migration bypasses outlive their reason by defaultA time-limited permission set assignment (admin/permission-set-expiration)

What a proper configuration adds over just creating the permission: the flag means one thing, every context that reads it uses the right syntax, the grant path is a permission set you can audit and expire, and there is a query that answers "who holds this today" without a Setup click-through.


Core Concepts

What Custom Permissions Are

Custom permissions are named boolean access grants. Unlike CRUD, FLS, and tab access, they carry no implicit meaning to the platform — they exist solely so developers and admins can build their own feature gates. Each custom permission has a label and an API name and can optionally be tied to a Connected App. When granted, the permission evaluates to true in every supported context for that running user's session.

Source: Salesforce Help — Custom Permissions Overview

Creating Custom Permissions

Custom permissions are created in Setup > Custom Permissions. Click New, enter a label and an API name, then optionally provide a description and a Connected App association.

Key constraints on the API name (CustomPermission.DeveloperName, Object Reference):

  • Must begin with a letter, and must not include spaces.
  • Only alphanumeric characters and underscores are allowed.
  • Must not end with an underscore, and must not contain two consecutive underscores — __ is the namespace separator (NamespacePrefix__componentName).
  • Limit 80 characters, unique in the org.
  • Cannot be changed after the permission is referenced in production without a coordinated update of all dependent metadata and code.

label and connectedApp are capped at 80 characters and description at 255 (Metadata API Developer Guide, CustomPermission field table).

The CustomPermission metadata type is supported by the Metadata API (version 31.0 and later) and SFDX source format. The file lives at customPermissions/My_Custom_Permission.customPermission-meta.xml, and the filename stem is the API name — there is no <fullName> element in source format. Deployable shapes, package.xml, and the verification queries are in references/metadata-examples.md.

Assigning Custom Permissions to Permission Sets

Grant custom permissions through permission sets. In Setup, open a permission set, navigate to Custom Permissions, and enable the desired permission. In the Metadata API, the permission set XML includes a <customPermissions> node (PermissionSetCustomPermissions, API 31.0+):

xml
<?xml version="1.0" encoding="UTF-8"?>
<PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
    <label>Refund Pilot</label>
    <customPermissions>
        <enabled>true</enabled>
        <name>My_Custom_Permission</name>
    </customPermissions>
</PermissionSet>

A single custom permission can appear in multiple permission sets and permission set groups. When any one of those is assigned to a user, the permission evaluates to true for that user.

Profile accepts the identical shape through ProfileCustomPermissions, also from API version 31.0. It deploys, and it hides — see references/gotchas.md Gotcha 1 and admin/permission-sets-vs-profiles. Permission set structure, grouping, and muting are admin/permission-set-architecture.

Checking Custom Permissions in Each Platform Context

Validation Rules and Formula Fields

Use the $Permission global merge field. This returns true or false:

$Permission.My_Custom_Permission

To let users with the permission bypass a validation rule:

AND(
  NOT($Permission.My_Custom_Permission),
  /* original rule conditions */
)

Source: Salesforce Help — Use Custom Permissions in Formulas

Apex

Use FeatureManagement.checkPermission(String apiName). It returns a Boolean and does not consume a SOQL row or any measurable governor resource:

apex
if (FeatureManagement.checkPermission('My_Custom_Permission')) {
    // user holds the permission — allow the action
}

Source: Apex Developer Reference — FeatureManagement Class

Flow

$Permission is a global resource available in Flow, but only as a formula resource — not directly in a Decision element condition row. The pattern is:

  1. Create a formula resource of type Boolean with the value $Permission.My_Custom_Permission.
  2. Reference that resource variable in a Decision element condition.

Visualforce

{!$Permission.My_Custom_Permission}

This evaluates to the string "true" or "false" in merge field contexts, or as a Boolean in rendered attributes.

Lightning Page Component Visibility, Dynamic Forms, and In-App Guidance

Component-visibility filters use a different grammar — note the extra CustomPermission. segment:

{!$Permission.CustomPermission.My_Custom_Permission}

Supported for app, Home, and record pages only (Metadata API Developer Guide, FlexiPage component-visibility expressions; the same expression appears in Prompt.uiFormulaRule). Owned by admin/dynamic-forms-and-actions and admin/in-app-guidance-and-walkthroughs.

LWC

javascript
import hasPerm from '@salesforce/customPermission/My_Custom_Permission';

The import resolves to true or undefined, never false, and it shapes the DOM rather than enforcing anything. The Apex method behind the component needs its own check. Owned by apex/apex-custom-permissions-check.

Connected Apps

The CustomPermission metadata type has a connectedApp field: "The name of the connected app that's associated with this permission. Limit: 80 characters." UNVERIFIED (2026-09-04): the Metadata API guide does not document what that association enforces at authorization time, and the CustomPermission sObject exposes no connected-app field to query it back — do not promise an access_denied on OAuth. To require permissions for a connected app, the grounded field is ConnectedApp.permissionSetName (API 46.0+), which needs isAdminApproved set to true.


Common Patterns

Pattern: Feature Gate for Beta or Graduated Rollout

When to use: A new feature is ready for testing by a subset of users before general availability. You want to control who sees it without a code deployment.

How it works:

  1. Create a custom permission: API name Beta_New_Case_Console.
  2. Create a permission set: Beta Testers — Case Console. Add the custom permission to it.
  3. Assign the permission set to pilot users only.
  4. In an LWC, call a @AuraEnabled(cacheable=true) Apex method that returns FeatureManagement.checkPermission('Beta_New_Case_Console').
  5. Conditionally render the feature component based on the returned Boolean.
  6. Guard the Apex action itself with the same check so the gate cannot be bypassed via API.
  7. Expand rollout by assigning the permission set to more users — no code change required.

Why not the alternative: A custom Boolean field on the User object requires a SOQL query in Apex and cannot be read by $Permission in formulas. FeatureManagement.checkPermission is instant, session-accurate, and has no governor-limit cost.

Pattern: Admin-Only Bypass in Validation Rules

When to use: A validation rule must enforce data quality for regular users but admins or integration users need an escape hatch without deactivating the rule.

How it works:

  1. Create a custom permission: Bypass_Validation_Rule_Account.
  2. Add it to the integration user's permission set.
  3. Wrap the existing validation rule with an outer AND condition:
AND(
  NOT($Permission.Bypass_Validation_Rule_Account),
  /* original rule conditions here */
)

Why not the alternative: $Profile.Name is fragile — profiles get renamed and new admin profiles would require a rule update. Custom permissions decouple the bypass from profile identity entirely.

Pattern: Conditional UI Visibility Gate in LWC

When to use: A button, panel, or action should only appear for users with a specific named entitlement, and server-side enforcement is required.

How it works:

  1. Create a custom permission: View_Refund_Controls.
  2. Expose an Apex wire adapter or @AuraEnabled method that returns FeatureManagement.checkPermission('View_Refund_Controls').
  3. In the LWC template, use lwc:if to conditionally render the element.
  4. In the Apex action handler, repeat the check before executing any sensitive logic.

Decision Guidance

SituationRecommended ApproachReason
Gate a feature for a named group of usersCustom permission on a permission setNamed, auditable, toggleable without code change
Bypass a validation rule for integration usersNOT($Permission.My_Permission) as outermost ANDDecoupled from profile identity, survives renames
Check access in ApexFeatureManagement.checkPermission('ApiName')No SOQL, no governor limit cost, session-accurate
Check access in FlowFormula resource of type Boolean: $Permission.ApiName$Permission is only available inside formula resources
Check access in Visualforce{!$Permission.ApiName} in rendered attribute or expressionGlobal merge field works natively in VF
Grant the permission to specific usersAdd to a dedicated permission set and assign that setCannot assign a custom permission directly to a profile
Verify access in an Apex testAssign the permission set to the test user in @TestSetupFeatureManagement.checkPermission returns false in test context without explicit perm set assignment

Recommended Workflow

  1. Answer the seven questions above and fill templates/custom-permissions-template.md. The consumer list you produce there is the input to every later step; if the permission's purpose needs an "and", split it into two permissions now.
  2. Baseline the existing grants. Run the SetupEntityAccess -> PermissionSetAssignment query in references/metadata-examples.md for the permission (or for SetupEntityType = 'CustomPermission' org-wide) and read PermissionSet.IsOwnedByProfile — profile-borne grants will not show up anywhere else (references/gotchas.md Gotcha 1).
  3. Author the .customPermission-meta.xml from the matching shape in references/metadata-examples.md (feature flag, bypass, dependent, or connected-app). Write a description that names the consumers; leave isLicensed out entirely — it is read-only (Gotcha 7).
  4. Author the grant as a <customPermissions> node in a permission set, not a profile. For a bypass, decide expiry here and use admin/permission-set-expiration if the grant is temporary.
  5. Write each consumer in its own syntax — NOT($Permission.X) for validation rules (contract in templates/admin/validation-rule-patterns.md), a Boolean formula resource for Flow, FeatureManagement.checkPermission('X') for Apex, @salesforce/customPermission/X for LWC, and {!$Permission.CustomPermission.X} for component visibility. The last one is the one that gets copied wrong (Gotcha 6).
  6. Lint, then validate. Run python3 skills/admin/custom-permissions/scripts/check_custom_permissions.py --manifest-dir <dir> — it flags dangling grants as ERROR, missing requiredPermission targets, empty descriptions, and $Permission.X / checkPermission('X') references to permissions absent from the tree. Then sf project deploy validate, deploying definitions before grants before consumers.
  7. Verify in the org and record the evidence. Re-run the SetupEntityAccess query and keep the result as the access-review artifact; a metadata diff cannot prove a revocation (Gotcha 8). Work the Review Checklist below.

Review Checklist

  • Custom permission API name starts with a letter and contains only alphanumeric characters and underscores.
  • Permission is added to at least one permission set (not directly to a profile).
  • All platform contexts that check the permission use the correct syntax for their context.
  • Apex unit tests assign the permission set to the test user via System.runAs and a PermissionSetAssignment insert.
  • Validation rule bypass uses NOT($Permission.X) as an outer AND condition so the original rule logic is preserved.
  • The custom permission metadata file and updated permission set XML are committed to source control.
  • check_custom_permissions.py has been run on the metadata directory and reports no ERROR.
  • Every custom permission has a non-empty description naming its consumers.
  • description is under 255 characters (CP-DESC-01 ERROR) and ideally under 200 (CP-DESC-02 INFO, headroom only) — if the consumer list alone does not fit, split the permission rather than compressing it.
  • isLicensed does not appear in any authored .customPermission-meta.xml (it is read-only).
  • Component visibility filters use {!$Permission.CustomPermission.X}, not the formula spelling.
  • Any requiredPermission target ships in the same deployment package as its parent.
  • Grants were verified in the org with the SetupEntityAccess query, and IsOwnedByProfile was checked for hidden profile grants.

Salesforce-Specific Gotchas

  1. Grant through permission sets, not profiles — but know that a profile grant deploys — Profile.customPermissions exists in the Metadata API from version 31.0, the same version as the permission set element. A profile-borne grant is real and is invisible in the Custom Permissions related list. Full detail in references/gotchas.md Gotcha 1.

  2. Apex test classes do not inherit the running user's real permission sets — FeatureManagement.checkPermission() returns false in test context unless you explicitly create the permission set, add the custom permission to it, and assign it to the test user with a PermissionSetAssignment record inside System.runAs. Skipping this causes false-passing tests in development environments that have the permission set already assigned.

  3. $Permission in Flow is only available inside formula resources — it cannot be typed directly into a Decision element condition row. Create a formula resource (type: Boolean) with value $Permission.My_Permission, then reference that resource in the Decision element.

  4. API name changes break all references without warning — renaming a custom permission does not cascade to validation rules, formula fields, or Apex code. Formulas referencing the old name silently evaluate to false; Apex code fails at deploy time if the reference is in a compile-time string but may silently fail at runtime in dynamic contexts. Treat the API name as immutable once the permission is in production.

  5. A description over 255 characters fails the deploy — the consumer list (the only place it survives, Gotcha 9) plus any rationale text overflows the Metadata API's 255-character CustomPermission.description limit fast; scripts/check_custom_permissions.py flags it (CP-DESC-01 ERROR at 255+, CP-DESC-02 INFO headroom at 200+) before the deploy does.


Output Artifacts

ArtifactDescription
Custom permission metadataCustomPermission XML file deployable via SFDX or Metadata API
Permission set updateUpdated .permissionset-meta.xml containing the <customPermissions> node
Apex guard clauseFeatureManagement.checkPermission call wrapped in a helper method with test coverage pattern
Validation rule expressionNOT($Permission.X) bypass wrapper for existing validation rule formulas
Checker reportOutput of check_custom_permissions.py: coverage table, ERROR on dangling grants, WARN on missing dependency targets, empty descriptions, and undefined $Permission / checkPermission references
Access evidenceSetupEntityAccess -> PermissionSetAssignment result set, timestamped, from references/metadata-examples.md

Reference Files

FileRead it when
references/metadata-examples.mdWriting or reviewing the deployable XML, package.xml, deploy order, or the SetupEntityAccess verification queries
references/gotchas.mdA permission "isn't working", a grant cannot be explained, or a metadata diff is being used as access evidence
references/examples.mdWorking an end-to-end scenario: beta gate, validation-rule bypass, or the Apex test-setup pattern
references/well-architected.mdJustifying custom permission vs custom setting vs permission set license, or citing the source behind a claim
references/llm-anti-patterns.mdReviewing AI-generated custom permission guidance before it ships
templates/custom-permissions-template.mdStarting a task — capture the API name, consumer list, and grant plan before authoring metadata

Related Skills

  • admin/permission-set-architecture — use when the question is how to structure permission sets and groups, not how to create or check a custom permission.
  • admin/permission-sets-vs-profiles — use when deciding whether a grant belongs on a profile at all; owns the migration argument behind Gotcha 1.
  • admin/permission-set-expiration — use when a bypass or pilot grant must expire on a date rather than be remembered.
  • admin/validation-rules — use when validation rule logic is the primary concern and the custom permission is only the bypass mechanism; owns the NOT($Permission.X) bypass contract with templates/admin/validation-rule-patterns.md.
  • admin/dynamic-forms-and-actions — use for field and component visibility rules; owns the {!$Permission.CustomPermission.X} filter syntax.
  • admin/in-app-guidance-and-walkthroughs — use for prompts and walkthroughs; owns uiFormulaRule targeting on custom permissions.
  • admin/flow-for-admins — use when the check happens inside a Flow; owns the Boolean formula-resource pattern.
  • apex/apex-custom-permissions-check — use when the gate lives in Apex or LWC; owns FeatureManagement.checkPermission, the @salesforce/customPermission import, managed-package namespacing, and the test patterns.
  • security/security-health-check — use when auditing org-wide access and permission hygiene at scale.

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Custom Permissions AI 技能有什么作用?

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.

为什么在 TypingMind 中使用 Custom Permissions?

因为您只需安装一次,就能搭配任何模型使用。Custom Permissions 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Custom Permissions?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/PranavNagrecha/AwesomeSalesforceSkills/tree/main/skills/admin/custom-permissions。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Custom Permissions?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Custom Permissions 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Custom Permissions 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Custom Permissions AI 技能免费吗?

PranavNagrecha 已在 GitHub 上发布了该技能。请查看代码仓库了解许可条款。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇