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 Get Into Salesforce With No Experience
Wondering if you can get a Salesforce job with no experience? Learn how to pick a career path, build real skills, and land your…
Salesforce How to Become a Salesforce Developer Without Experience
No coding background? Learn how to become a Salesforce Developer step by step - skills to build, projects to create, and how to…
Salesforce How to Become a Salesforce Admin With No Experience
No Salesforce Admin experience? Learn how to build real skills, create projects, and land an entry-level Salesforce Admin job…
Salesforce How Long Does It Take to Become a Salesforce Developer?
Wondering how long to learn Salesforce Developer? Most beginners need 6–12 months. See the study time, stage-by-stage roadmap and…