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

Displaying custom Validation error message in Visualforce pages

I have some additional fields on my VisualForce page that are not part of the Case Object.  I don't know how to add those validation errors to the system generated validation errors (AccountID, ContactID, etc) that I display on the page. 


I use the following:

 ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Asset:  You must enter a value'));

HOWEVER this only appears AFTER I have resolved all the system validations errors.  I don't want them to have to click 2x if they have errors.


I also tried ===immediate="true"=== on the button that I have.

HOWEVER then I don't see any of the object data(AccountID, ContactID, etc).


Any idea what to do?



Perhaps adding addError() method in a trigger. As follows:


trigger CaseValidation on Case (before insert, before update) {
	for (Case kase : {
		if (kase.Foo__c == 'INVALID')
			kase.addError('Some error message');



I am not using a trigger.  It is just a Class with a Page. I think I may remove the <apex:message> from the page and put in my own section.