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
saharisahari 

How to customise the errors displayes in Sites pages

I have a developed a vf page which has a form in it. And when ever the user does not fill teh reqd fields. the page is getting reloaded. So I added

<apex:pageMessages>

 

Now I get the error msg displayed on the page top. But this msg is not user understandable. How can I customize this error or just print a neat msg./? I have tried

ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Email is required field'));  this in the associated class. But I still the get the same following msg.

 

Any help is greatly appreciated.

 

 
ERROR
Error: j_id0:j_id1:j_id52: Validation Error: Value is required.
Best Answer chosen by Admin (Salesforce Developers) 
Ronen.ax767Ronen.ax767

Hi , 


The most simple way to edit exception is to make an exception by your own validaion rule in the back code.

 

 

public virtual class MyException extends Exception{}

String errorMsg = "Error MSG to user - MyFieldToValidate field is empty please fill it up";

public pagereference SubmitFormButton() {

	if (MyFieldToValidate==null){

		Apexpages.addMessages(new  MyException(errorMsg));
	        return null;
	}
	
}

 

Add <apex:pagemessages escape="false" /> at top the of the page

and make sure you don't write required="true" in the VF page field (ex. <apex:inputField value="{!MyFieldToValidate}">)


hope this help!

All Answers

Scott.MScott.M

I haven't found any way to customize those errors. If someone else knows of a way I'd love to know!

 

I think those errors occur when the validation is done at the visualforce level by setting the required attribute to true in the <apex:input>. The only way around this I've found is to set the required attribute to false and do the validation server side then output the error in the controller the way you tried.

 

Scott

Ronen.ax767Ronen.ax767

Hi , 


The most simple way to edit exception is to make an exception by your own validaion rule in the back code.

 

 

public virtual class MyException extends Exception{}

String errorMsg = "Error MSG to user - MyFieldToValidate field is empty please fill it up";

public pagereference SubmitFormButton() {

	if (MyFieldToValidate==null){

		Apexpages.addMessages(new  MyException(errorMsg));
	        return null;
	}
	
}

 

Add <apex:pagemessages escape="false" /> at top the of the page

and make sure you don't write required="true" in the VF page field (ex. <apex:inputField value="{!MyFieldToValidate}">)


hope this help!

This was selected as the best answer