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
InternalServerErrorInternalServerError 

How to avoid page refresh on validation

Currently, with the code below, when a user clicks on the OK button, if there is a validation error the page refreshes, if not the record saves successfully and the user is redirected to another page. How can I avoid the page refresh without losing the validation message displaying on the page?.

 

Or, how can I force the user to select an option (this field is a picklist) to be able to click on the OK button, this would avoid having to deal with the validation.

 

VF:

 

<apex:message/>

<apex:inputField id="reasonres" required="true" value="{!case.Reason_Resolved__c}"  />
   
<apex:commandButton action="{!closecase}" value="OK"  />

 

controller:

 

public PageReference closecase() {
        
     caseobj.status='closed';
       
     if( caseobj.Reason_Resolved__c == null ) {
   
    caseobj.Reason_Resolved__c.addError('Please select a close reason');
    
     return null;
      }else{
      
       
     caseController.save();
     
      return Page.MySupport;}
       
     }

 

 

Thanks.

 

 

Suresh RaghuramSuresh Raghuram

<apex:message immediate = "true">

 

That will execute the error message or a validation rule voilation first before getting refresh.

 

If this answers your question please make this as solution.

InternalServerErrorInternalServerError
Suree,
That attribute doesn't seem to be available for apex:message. :(
"Error: Unsupported attribute immediate in <apex:message> "
sivaextsivaext

Hi 

 

you already given "required" in put field. the picklist is "--NONE" treated as blank value.

salesforce itself gives standard validation.

 

why using add error message ?

InternalServerErrorInternalServerError

Hi Sivaext,

 

I was trying many ways to do this, but regardless of using the standard validation or a custom validation, the page always refreshes if any type of validation is triggered.  :(

Suresh RaghuramSuresh Raghuram

k

 

this the situation i came across and got success with that

 

the thing is

<apex:pageMessage id="msg1"/>

 

in the command button i am rendering this message

<apex:commandButton action={!Save} reRender="msg" immediate="true"/>

 

This is working fine by overcomming most of the errors i came across

Try it

vaishali sharmavaishali sharma
Hi ,did we get the solution of this problem ? I am facing the same problem.