function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
How we'll use Custom label in apex code in which we'll take the label name dynamically???
Hi Puja,
You cant do that in apex, however it can be done in visualforce page using global variable that you can provide the custom label name at runtime.
The following example illustrate this :
//-------------------- Controller-----------------------
public class MyController
{
public String mylabel{get; set;}
public MyController()
mylabel='Test_label'; // provide custom label name as you have, in my case it is Test_Label
}
//----------------VF Page ------------------------
<apex:page Controller="MyController">
<apex:outputText> {!$Label[mylabel]} </apex:outputText>
</apex:page>
Hope it would help u.
Hi,
Custom labels are not standard sObjects. You cannot create a new instance of a custom label. You can only access the value of a custom label using system.label.label_name in Apex script.
for more about custom Label go through the below link :
https://ap1.salesforce.com/help/doc/user_ed.jsp?section=help&target=cl_about.htm&loc=help&hash=topic-title
Try the below code snippet as reference:
=== Vf page==============<apex:page controller="clscustomlabelvalue" ><apex:outputText value="{!test1}"></apex:outputText></apex:page>
== Apex Controller===========public class clscustomlabelvalue{public string test1{get;set;}public clscustomlabelvalue (){test1=Label.test;}}
You can access the custom label values dynamically by using the below statement.
String test = Label.<custom label name>;
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Hi
I don't want to directly pass the custom label name like : "Label.<Custom Label Name>"....I want to use some variable for this like :
String Str = "Custom_label _Name";
String value = System.Label.str;
Hi Alok
Thanks For Help .it's working for me .
Hi Alok,
Great post! Your solution saved me. Great work figuring out that those square brackets would do the job :-)
Matt
string labelName = 'DemoLabel'; Component.Apex.OutputText output; output = new Component.Apex.OutputText(); output.expressions.value = '{!$Label.' + labelName + '}'; string labelValue = string.valueOf(output.value);
Hi Puja,
You cant do that in apex, however it can be done in visualforce page using global variable that you can provide the custom label name at runtime.
The following example illustrate this :
//-------------------- Controller-----------------------
public class MyController
{
public String mylabel{get; set;}
public MyController()
{
mylabel='Test_label'; // provide custom label name as you have, in my case it is Test_Label
}
}
//----------------VF Page ------------------------
<apex:page Controller="MyController">
<apex:outputText> {!$Label[mylabel]} </apex:outputText>
</apex:page>
Hope it would help u.
All Answers
Hi,
Custom labels are not standard sObjects. You cannot create a new instance of a custom label. You can only access the value of a custom label using system.label.label_name in Apex script.
for more about custom Label go through the below link :
https://ap1.salesforce.com/help/doc/user_ed.jsp?section=help&target=cl_about.htm&loc=help&hash=topic-title
Hi,
Try the below code snippet as reference:
=== Vf page==============
<apex:page controller="clscustomlabelvalue" >
<apex:outputText value="{!test1}"></apex:outputText>
</apex:page>
== Apex Controller===========
public class clscustomlabelvalue
{
public string test1{get;set;}
public clscustomlabelvalue ()
{
test1=Label.test;
}
}
You can access the custom label values dynamically by using the below statement.
String test = Label.<custom label name>;
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Hi
I don't want to directly pass the custom label name like : "Label.<Custom Label Name>"....I want to use some variable for this like :
String Str = "Custom_label _Name";
String value = System.Label.str;
Hi Puja,
You cant do that in apex, however it can be done in visualforce page using global variable that you can provide the custom label name at runtime.
The following example illustrate this :
//-------------------- Controller-----------------------
public class MyController
{
public String mylabel{get; set;}
public MyController()
{
mylabel='Test_label'; // provide custom label name as you have, in my case it is Test_Label
}
}
//----------------VF Page ------------------------
<apex:page Controller="MyController">
<apex:outputText> {!$Label[mylabel]} </apex:outputText>
</apex:page>
Hope it would help u.
Hi Alok
Thanks For Help .it's working for me .
Hi Alok,
Great post! Your solution saved me. Great work figuring out that those square brackets would do the job :-)
Matt
Hope this helps...
Can we do it in a formula or validation rule ?
Sharad
{!$Label.c.My_Custom_Label}
From a Lightning component JavaScript perspective it's:
$A.get("$Label.c.My_Custom_Label");
From a Visualforce page perspective it's:
{!$Label.My_Custom_Label}
From an Apex class perspestive it':
Label.My_Custom_Label