function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Shraddha AhireShraddha Ahire 

Can we localized standard page messages like "required" message on vf page?

I have to localize this standard "Validation Error: Value is required.". Is there a way in salesforce to localized such standard messages?
 
Ahmed Ansari 13Ahmed Ansari 13
Hii Shraddha Ahire,

Yes You can, for this work around you can follow the below Steps

Steps :
Step 1: First we need to use required="false" for that field as shown in the below piece of code.
<apex:inputField value="{!acc.name}" required="false"/>
Step 2: To make that field required use the sample code below.
<apex:pageBlockSectionItem > Account Name
   <apex:outputPanel layout="block" style="float: left">
  <apex:outputPanel >
<div class="requiredInput"><div class="requiredBlock"/>
  <apex:inputField value="{!acc.name}" required="false" />          
</div>
  </apex:outputPanel>                              
   </apex:outputPanel>
</apex:pageBlockSectionItem>

Example :
Apex Class : StandardErrorOverrideController
public class StandardErrorOverrideController {
    public account acc {get;set;}
    public StandardErrorOverrideController() {
        acc = new Account();
    }
    public void saveData() {

        try {
        insert acc;
        } catch(DMLException e) {
            if(acc.name =='' || acc.name == null) {
                acc.name.addError('Account Name Cannot be Null');
            }
        }       
   }    
}
Visualforce Page :
<apex:page controller="StandardErrorOverrideController">
<apex:form >
    <apex:pageBlock title="My Content" mode="edit">
        <apex:pageBlockButtons >
            <apex:commandButton action="{!saveData}" value="Save"/>
        </apex:pageBlockButtons>
        <apex:pageBlockSection title="My Content Section" columns="2">
             <apex:pageBlockSectionItem > Account Name
               <apex:outputPanel layout="block" style="float: left">
                      <apex:outputPanel >
                            <div class="requiredInput"><div class="requiredBlock"/>
                                  <apex:inputField value="{!acc.name}" required="false" />          
                            </div>
                      </apex:outputPanel>                              
               </apex:outputPanel>
            </apex:pageBlockSectionItem>
            <apex:inputField value="{!acc.site}"/>
            <apex:inputField value="{!acc.type}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>
</apex:page>

Regards,
Ahmed Ansari
Shraddha AhireShraddha Ahire
Thanks for reply. Can we do keeping "required" equal to true.
Ahmed Ansari 13Ahmed Ansari 13
NO, if you use Your Custom message than required equal to false