+ Start a Discussion

Dynamic Custom Label

Is there a possibility to use dynamic custom labels in apex. I know you can do this with VF, but i can't find it for apex. 


Custom label = 'You have used {0} in {1} Hours'


in apex


String text = Label.used(List<String>('12','2');


Best Answer chosen by Admin (Salesforce Developers) 

in spring12 this feature is there..... 

All Answers



You can try the below code sample


<apex:page controller="clsActionSupport">

  <apex:form >

   <apex:pageBlock >

     <apex:outputPanel id="Text">

         <apex:outputText value="{!count}"> </apex:outputText>

         <apex:actionPoller reRender="Text" interval="5" action="{!increment}"/>







public class clsActionSupport


    integer count =0;

    public pagereference increment()


        count = count + 1;

        return null;


    public integer getcount()


      return count;




Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 




No this is not what i mean.

Custom label is used for translations of text in visualforce and apex. It is an salesforce object. 


but u can try like this

<apex:outputText value="{!$Label.customlabel}">

	<apex:param value="{!value}"/>


I know that solution as well. I need it in a purely apex method. For if you wish to add custom text to an email or use it in a trigger. 




in spring12 this feature is there..... 

This was selected as the best answer

Okay thanks!


Are not you looking for the following syntax? This has been there for a long time.


String text = String.format(System.Label.used, List<String>('12','2'));
lakhwinder singh 13lakhwinder singh 13
For Example custom label :-  LabelName = ' Name is {0} is incorrect.';
String errorMessage = System.Label.LabelName ;
        for(Account obj: accountList){
            if(Obj.Name != 'TestAccount'){
              dataTableSetting.addError(String.format(errorMessage, new List<String>{obj.Name}));