+ Start a Discussion
StenEStenE 

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) 
kiranmutturukiranmutturu

in spring12 this feature is there..... 

All Answers

Navatar_DbSupNavatar_DbSup

Hi,

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}"/>

     </apex:outputPanel> 

  

   </apex:pageBlock>

  </apex:form>

</apex:page>

 

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. 

 

 

StenEStenE

No this is not what i mean.

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

kiranmutturukiranmutturu

but u can try like this

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

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

</apex:outputText>
StenEStenE

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. 

 

 

kiranmutturukiranmutturu

in spring12 this feature is there..... 

This was selected as the best answer
StenEStenE

Okay thanks!

dipu2dipu2

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'));