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
uptime_andrewuptime_andrew 

Custom Save - Validation Rules Cause Error

When I develop Visualforce pages with extensions containing custom saves, the validation rules I've setup will cause errors (e.g. an ugly error page), rather than showing the validation error gracefully on the page.

 

Have other developers encountered this?  Is there a way to invoke the validation errors and show the errors gracefully in the page rather than displaying an ugly eror page.

Ispita_NavatarIspita_Navatar

Are you using the <apex:messages> tab in your pages? If no then please do for preventing the deformation of your pages.

 

Please note if a user enters data on a Visualforce page that uses a standard controller, and that data causes a validation rule error, the error can be displayed on the Visualforce page. If the validation rule error location is a field associated with an <apex:inputField> component, the error displays there. If the validation rule error location is set to the top of the page, use the <apex:pageMessages> or <apex:messages> component within the <apex:page> to display the error.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.

ncramerncramer

Andrew,

 

This was my solution to the same problem. If there's a simple one, I'd be interested, as this is a bit tedious to include in all cases:

 

 

 	try {
		insert eqt;
 	} catch (DmlException dmle) {
 		if(dmle.getDmlType(0) == StatusCode.FIELD_CUSTOM_VALIDATION_EXCEPTION) {
 			ApexPages.addMessages(dmle);
	                return null;
 		} 
 		else throw dmle;
		     		
 	}