function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Arjun Mohan 6Arjun Mohan 6 

How to Change Label Name dynamically in component?

Hi All,
I have created a Component where admins can drag and drop my component where ever they want. but i need to change the label name dynamically.
I.e., when admins drag and drop my component to page i need to show a pop up for asking label name. what ever admin enter should be my label name in component..
any suggestion would be of great help
Thanks Arjun.M
EldonEldon
Hi Arjun,

We can't reference labels dynamically in apex. You can vote for this idea here (https://success.salesforce.com/ideaView?id=08730000000hhVGAAY). However, you can reference them dynamically from visualforce so you can put them on the page like so:
public class MyController
{
    public String mylabel{get; set;}

    public MyController()
    {
         mylabel='labelname';   
    }
}

<apex:page Controller="MyController">
    <apex:outputText> {!$Label[mylabel]} </apex:outputText>
</apex:page>

maybe you can add this VF in your component. I havent done this. You can try though

Regards