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
lakshman.mattilakshman.matti 

scroll back to error messages in VF page

HI All,

I have created a visualforce page which contains many inputfileds to accept values from user. i'm showing some visualforce error messages on top of the page, if user forgets to enter values in inputfields. 
what i want here is whenever user enters some values and clicked on submit button,if it shows any errors it should automatically go back to the the place where error messages are displyed.(i.e we need to set focus on Error messages.)
I hope my question is clear.
Any suggestions or code snippet is appriciated.


Thanks
Lakshman
 
Amit Chaudhary 8Amit Chaudhary 8
Please check below post. I hope that will help you
1) http://www.sfdcpoint.com/salesforce/show-error-message-visualforce-page/
2) http://www.infallibletechie.com/2013/04/how-to-add-error-message-in-visualforce.html
3) http://www.infallibletechie.com/2012/10/how-to-display-error-messages-in.html
 
<apex:page standardController="Account" extensions="ErrorMessageInVfController">
 <apex:form >
   <apex:pageblock >
      <apex:pageMessages id="showmsg"></apex:pageMessages>
         <apex:panelGrid columns="2">
           Account Name: <apex:inputText value="{!acc.name}"/>
           Account Number: <apex:inputText value="{!acc.AccountNumber}"/>
           Account Phone: <apex:inputText value="{!acc.phone}"/>
           Account Site: <apex:inputText value="{!acc.site}"/>
           Account Industry: <apex:inputText value="{!acc.industry}"/>
           <apex:commandButton value="Update" action="{!save}" style="width:90px" rerender="showmsg"/>
         </apex:panelGrid>
    </apex:pageblock>
 </apex:form>
</apex:page>
 
public with sharing class ErrorMessageInVfController {
    public Account acc{get;set;}
    public ErrorMessageInVfController(ApexPages.StandardController controller) {
        acc = new Account();
    }
 
    public void save(){
      if(acc.name == '' || acc.name == null)
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Please enter Account name'));
 
      if(acc.AccountNumber == '' || acc.AccountNumber == null)
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter Account number'));
 
      if(acc.phone == '' || acc.phone == null)
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please enter Account phone'));
 
      if(acc.site == '' || acc.site == null)
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Please enter Account site'));
 
      if(acc.industry == '' || acc.industry == null)
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Please enter Account industry'));
 
    }
}

Let us k now if this will help you

Thanks
Amit Chaudhary


 
lakshman.mattilakshman.matti
Hi amit,

Thanks for your reply.
I think u didnt understand my question. you came to to half in the solution.
so my question is u have several fields in the form say 20.think like there are few mandatory.
we have a button down in the page(bottom of the page.) because u have more fields in the page we will get scroll bar. here comes my question, when u click on that button without giving few mandatory values page will give error messages on the top of the page.but u cant see them until and unless u scroll to top of page.
i want this scrolling to be automatic, that means whenever u get error message in the we should automatically go back to the place where error msgs are displyed.
i hope my question is clear now. 

thanks
Lakshman