How to access custom labels dynamically in visualforce page?

No, you can’t reference labels dynamically in apex.
However, you can reference them dynamically from visualforce so you can put them on the page like so:

Apex Class:
public class MyController
{
public String mylabel{get; set;}

public MyController()
{
mylabel=’CustomLabelName‘;
}
}

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

Written by 

Salesforce MVP | Lightning Champion | 16x Salesforce Certified | Application Architect | 6x Trailhead Ranger | Techforce Services | Australia

Leave a Reply

Your email address will not be published. Required fields are marked *

*