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 Entry-Level Salesforce Admin Salary: What Can You Expect to Earn?
Curious what an entry-level Salesforce Admin actually earns? See real salary benchmarks by experience and location, plus how to…
Salesforce Senior Salesforce Admin Salary: Salary Range, Factors & Career Growth
What does a senior Salesforce administrator actually earn? See real salary ranges, the skills that boost pay, and how to move up…
Salesforce Cost of Salesforce Developer Certification: Exam Fees, Retakes & Hidden Costs
The cost of Salesforce developer certification is $200 per exam and $100 to retake. See taxes, discounts, hidden costs, and…
Salesforce Cost for Salesforce Certification: Exam Fees by Type, Retakes & Hidden Costs
Salesforce certification exam fees run $75 to $4,500, and most cost $200. See cost by role, retakes, taxes, discounts, and…