Back to insights

Security, Release Control & Custom Permissions

A custom permission is an entitlement—not a feature flag

JSBC Labs8 min read

One Boolean can hide two different decisions

A team deploys a new pricing service behind a custom permission. Pilot users receive the permission set, the Lightning component appears and Apex follows the new calculation path. When errors rise, support removes the assignment from the pilot group. The screen disappears, but an integration user still reaches the new path through automation because the permission check was implemented inconsistently. What looked like a release toggle was really a collection of access decisions with no single operational state.

The JSBC Labs position is that a custom permission is an entitlement—not a feature flag. Salesforce defines custom permissions as access checks for custom processes and apps, assignable through permission sets or profiles. That makes them excellent for answering, ‘May this user perform this capability?’ A production flag must answer a different question: ‘Should this capability be active here, for this audience, at this time?’ Treating those questions as one Boolean entangles security administration with release control.

Model authority separately from release state

A user can be authorised for a capability that is not yet released, and a feature can be released while a particular user remains unauthorised. Express that truth directly: the path is available only when the operational flag is enabled and the current actor has the required entitlement. Add business eligibility as a third decision when the capability depends on record state, geography, product or contract. These conditions may all evaluate to true or false, but they have different owners and lifecycles.

Security teams should own the permission model and assignment policy. Product or service owners should own flag activation, rollout cohorts and exit criteria. Business rules should remain in governed domain logic. Name each mechanism for the decision it represents: `Can_Approve_Refund` describes authority; `New_Refund_Engine_Enabled` describes release state. A permission named after a temporary project or sprint conceals the contract and tends to survive long after the rollout ends.

Use custom permissions for durable capability checks

Custom permissions work across several platform surfaces. Apex can call `FeatureManagement.checkPermission()`, formulas and validation rules can reference `$Permission`, and Lightning Web Components can import a static custom-permission reference. Salesforce notes that the LWC reference is resolved without a network call. These are useful primitives for a consistent capability such as approving a refund, bypassing a governed automation path or accessing a sensitive application function.

Keep the custom permission small and durable, then assign it through capability-based permission sets. Permission set groups can compose those sets for personas, while muting can remove an inherited permission from a group. Do not hard-code profile names, user IDs or a pilot list into logic. Review assignments as access grants: document the owner, approval route, intended population, expiry for temporary exceptions and evidence needed for recertification.

A hidden button is not enforcement

Using a custom permission to hide an LWC control improves the user experience, but it does not protect the underlying operation. Another component, Flow, API client or crafted request may still call the server-side action. Enforce the entitlement again at the authoritative boundary, alongside object, field and record access. A permission check should narrow access; it should not replace sharing, CRUD, field-level security or validation of untrusted inputs.

Map every invocation route before launch. For Apex, verify the custom permission and the relevant data access in the service that performs the change. For automation bypasses, Salesforce Architects recommends checking `$Permission` in precise Flow entry criteria or using `FeatureManagement.checkPermission()` in an Apex trigger framework. Bypass permissions deserve particularly strict assignment and monitoring because they intentionally suppress normal behaviour.

Store operational state as configuration

Salesforce Well-Architected guidance describes feature flags backed by custom metadata types or custom settings so deployment can be separated from release. Custom metadata is deployable, packageable and available from the application cache; Apex can retrieve records with methods such as `getInstance()` and `getAll()`. A flag record can carry more meaning than enabled or disabled: environment, audience key, start and end time, owner, fallback mode and change reference.

Choose storage from the operating model. Custom metadata suits governed configuration promoted through delivery processes. A hierarchy custom setting can support organisation, profile or user variation when that inheritance is genuinely required. Avoid mutable business data disguised as configuration, and avoid a generic flag table that becomes an unowned switchboard. Centralise evaluation in one service so Apex, Flow and UI consumers do not invent incompatible defaults.

Design the cohort rather than naming it

A canary release may combine an operational flag with a custom permission assigned to a small cohort. That is a valid composition: the flag controls whether the release is live, while the permission identifies authorised pilot users. Salesforce Well-Architected guidance recommends monitored canary cohorts for business-critical changes rather than immediate broad rollout. The permission set is therefore an audience input, not the complete flag system.

Define how users enter and leave the cohort, which integrations or background jobs participate and what happens when execution has no interactive user. Service identities often expose the weakness in user-only targeting. Use stable cohort criteria, record the assignment source and ensure the fallback path remains compatible with data already written by the new path. A rollback that restores the old screen but cannot read new data is not a rollback.

Give every flag a removal plan

Temporary branches create permanent complexity when nobody owns their retirement. Before deployment, record the flag owner, activation authority, intended cohort, success measures, stop conditions, maximum lifetime and cleanup change. Operational dashboards should show the active state, evaluation volume, error rate and outcome measures for both the new and fallback paths. Audit who changed the configuration and when, rather than relying on a permission-assignment history to explain a release decision.

Reserve flags for changes whose risk justifies parallel behaviour. Salesforce Well-Architected explicitly warns against using them for every minor change. Once the rollout is complete and evidence is acceptable, remove the fallback branch, obsolete configuration and temporary cohort assignment. Keep the durable custom permission only if it still represents a real business capability. The goal is safer release—not an expanding museum of switches.

Test the decision table, not only the enabled path

Build tests for every meaningful combination: flag off with and without entitlement, flag on without entitlement, flag on with entitlement, missing configuration, expired cohort, integration identity and unauthorised direct server call. Verify both behaviour and data access. Treat a missing flag record as a deliberate fail-safe state, not an accidental null path. Test rollback after the new path has written realistic records, and confirm that scheduled and asynchronous work evaluates the same policy.

Custom permissions and feature flags are both valuable because they make decisions explicit. They become dangerous when their similar Boolean shape erases their different meanings. Use permissions to govern who may act, configuration to govern what is released and business logic to govern when the action is valid. That separation gives security a stable entitlement model and delivery teams a measurable, reversible rollout mechanism—without asking one permission assignment to do both jobs.

Official references

Continue reading