About this question
This is a generic question
apex:outputText value="{**0**,date,MM'/'dd'/'yyyy}"
What I wanted to know is what is the 0 in value used for?
This is a generic question
apex:outputText value="{**0**,date,MM'/'dd'/'yyyy}"
What I wanted to know is what is the 0 in value used for?
Log in to share your answer and help other learners.
Log in to answerBest Answer · By JanBask Salesforce Expert
Answered on May 11, 2023
The value attribute on "apex:outputText" is a valid format. It must be a positive number, and of type Number, Date, Time, or Choice.
For more info please check this url
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_outputText.htm?search_text=apex:outputtext
As per String.format in Java and apex you can say.....
under documented Apex String API i.e.
String formattedString = String.format(String template, List arguments)
String.format(..) is again based on Java MessageFormat class, its documentation says :
Treat the current string as a pattern that should be used for substitution in the same manner as apex:outputText.
Nice part of this String API is that it supports basic text substitution for ex.
// Create a Template String, that has tokens of form {index} String templateString = 'Hello {0}, Good to see you in {1}'; // String argument list or array matching each {index} in Template String. String[] arguments = new String[] {'Ram' , 'India'}; // Call String.format() to get the token replaced String formattedString = String.format(templateString, arguments); System.debug(formattedString);
// output : Hello Ram, Good to see you in IndiaBad part about this String API is it only supports String arguments for token replacement. Though both Java’s MessageFormat and Visualforce apex:outputText tag accept non-string arguments like Date, Datetime & Currency and are capable of doing very smart formatting with them. For ex. in visualforce one can format date using outputText as follows.
output: The formatted time right now is: 2004.11.20 AD at 23:49:02 GMT
Similar Java example with more options would be
Object[] arguments = {
new Integer(7), new Date(System.currentTimeMillis()), "a disturbance in the Force"
};
String result = MessageFormat.format(
"At {1,time} on {1,date}, there was {2} on planet {0,number,integer}.", arguments);
output: At 12:30 PM on Jul 3, 2053, there was a disturbance
in the Force on planet 7.
Sadly, if you try to do something similar with Apex it always fails for StringException.
Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.
Step-by-step Salesforce guides from industry experts
Common Salesforce interview questions, answered
Guides, tips and career advice on Salesforce from JanBask experts.
Salesforce How to Become a Salesforce Administrator in 2027: A Step-by-Step Career Roadmap
Want to become a Salesforce Administrator? Get the complete 2026 roadmap skills, certification, salary & career path. Start your…
Salesforce Salesforce Admin Self Study vs Live Training: How to Choose the Right Path
Compare Salesforce Admin self-study and live training by cost, duration, flexibility, mentorship, and career support. Find the…
Salesforce How a Salesforce Admin Certification Shapes Your Career Growth
Wondering if a salesforce admin certification is worth it? See how it shapes hiring, salary, and long term salesforce admin…
Salesforce Salesforce Admin vs Developer Salary: Which Path Actually Pays More?
Salesforce admin vs developer salary: developers earn 15–25% more. See entry, mid and senior pay, why the gap exists, and how…