Salesforce custom label in Apex, Visualforce, AURA, LWC
Salesforce custom labels can be used across different Salesforce technologies, including Apex, Visualforce, Aura components, and Lightning Web Components (LWC). Here's how you can use custom labels in each of these contexts:
Apex:
In Apex, you can access custom labels using the System.Label global variable. Custom labels are referenced by their developer name.
String labelValue = System.Label.MyCustomLabel;
Visualforce:
In Visualforce pages, you can reference custom labels using the $Label global variable.
<apex:outputText value="{!$Label.MyCustomLabel}" />
Aura Components:
In Aura components, you can access custom labels using the $Label global value provider.
<aura:component>
<aura:attribute name="labelValue" type="String" default="{!$Label.MyCustomLabel}" />
</aura:component>
Lightning Web Components (LWC):
In Lightning Web Components, you can import and reference custom labels using the @salesforce/label scoped module.
import myCustomLabel from '@salesforce/label/c.MyCustomLabel';
<!-- HTML template -->
<template>
<p>{myCustomLabel}</p>
</template>
By using custom labels in your Apex code, Visualforce pages, Aura components, and Lightning Web Components, you can centralize and manage text values more effectively, improving the maintainability and flexibility of your Salesforce application.
Comments
Post a Comment