This is for creating multilingual applications by displaying information like help text or error messages in a user’s native language.
This are custom text values that can be accessed from Apex classes, Visualforce pages, Lightning pages, or Lightning components.
Steps:
- Setup | start typing enter Custom Labels | then select Custom Labels.
- Create a label | click New Custom Label | To edit a label | click Edit next to the custom label.
- Description field - Better to enter an easily recognizable term to identify this custom label. This description is used in merge fields.
- To mark the custom label as protected, select Protected Component.
- For Categories, enter some text to categorize the label. This field can be used in filter criteria when creating custom label list views. Separate each category with a comma. The total number of characters allowed in the Categories text box is 255.
- In the Value text box, enter text up to 1,000 characters. This value can be translated into any language that Salesforce supports.
- Save the label.
In your Apex class, reference the label with the syntax System.Label.MyLabelName
Example:
Aura Component
HTML
<aura:component controller="LabelController">
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:attribute name="mylabel" type="String"/>
{!v.mylabel}
</aura:component>
JS
({
doInit : function(component, event, helper) {
var action = component.get("c.getLabel");
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.mylabel", response.getReturnValue());
}
});
$A.enqueueAction(action);
}
})
CLASS
public with sharing class LabelController {
@AuraEnabled
public static String getLabel() {
String s1 = 'Hello World, ' ;
String s2 = System.Label.sampleCustomLabel; //This should an active Account to proceed further
return s1 + s2;
}
}
APP (to display)
<aura:application >
<c:sampleLabel/>
</aura:application>
Visual:
https://www.youtube.com/watch?v=epOCoE4EdcA
https://www.youtube.com/watch?v=q6g8rPwi50c
Reference: https://help.salesforce.com/s/articleView?id=sf.cl_about.htm&type=5
Comments
Post a Comment