Advanced 15 min read

Custom Labels and Custom Permissions

By the end of this lesson, you'll be able to:

  • Use Custom Labels for translatable, user-facing text instead of hardcoded strings
  • Understand Custom Permissions and why LWC checks them via Apex

Prerequisites: "Slots and Composition"

Custom Labels

import saveButtonLabel from '@salesforce/label/c.Save_Button_Label';

export default class MyForm extends LightningElement {
    labels = { save: saveButtonLabel };
}
<lightning-button label={labels.save}></lightning-button>

A Custom Label is a piece of user-facing text defined once in Setup and made translatable into any language the org supports — importing it from @salesforce/label/c.<LabelName> avoids hardcoding English text directly in a component, which would never adapt for non-English users (Lesson 6 covers internationalization in full).

Custom Permissions

@AuraEnabled(cacheable=true)
public static Boolean canApproveDiscounts() {
    return FeatureManagement.checkPermission('Can_Approve_Discounts');
}
import canApprove from '@salesforce/apex/PermissionController.canApproveDiscounts';

@wire(canApprove)
canApproveDiscounts;

A Custom Permission is an admin-configurable, custom access flag — beyond standard object/field-level security — that can be assigned to specific users or profiles. There is no direct client-side way to check one from LWC; it must be checked in Apex (via FeatureManagement.checkPermission) and exposed through an @AuraEnabled method, following exactly the cacheable=true/@wire pattern from Module 7.

Why This Matters in Real Projects

Hardcoded strings and permission checks baked directly into component logic are both common sources of real production problems — one breaks the moment a non-English user opens the org, the other breaks the moment an admin needs to grant a new team access without a code deployment.

Exercise

Import a Custom Label named Welcome_Message and use it as the text content in a paragraph.

Show hint

Import from @salesforce/label/c.<name>.

JAVASCRIPT

Exercise

Challenge: explain, as a comment, why a Custom Permission cannot be checked directly in LWC JavaScript, unlike a simple UI state check.

Show hint

Think about where permission data actually lives and who can be trusted to enforce it.

JAVASCRIPT

Custom Labels and Custom Permissions Quiz

1. Where are Custom Labels imported from in LWC?

2. What is the main purpose of a Custom Label?

3. How is a Custom Permission checked from LWC?

4. Why must Custom Permission checks happen in Apex rather than client-side JavaScript?

5. What real problem does hardcoding English text directly in a component cause?

Log in to submit the quiz and save your score.

My Notes

Log in to keep private notes on this lesson.

Questions about this lesson

No questions yet — be the first to ask.

Log in to ask a question about this lesson.

Summary

Custom Labels externalize user-facing text for translation, and Custom Permissions provide admin-configurable access checks beyond standard object/field security — both accessed from LWC through dedicated, purpose-built mechanisms.