I have a page that needs to be validated when the submit button is clicked. A couple of these components require validations such as "if this checkbox is checked as well as this other checkbox is checked then make sure this textbox has a value", so nothing an validation rules could do I believe. So I wrote an apex function called 'validate()' that does all of these checks and it works fine. The only problem is where to call the function. Right now I have it in the 'submit()' function so that if 'validate' fails it pops up error messages and if it passes it submits/saves the object. Still so far so good. The only problem is it doesnt mix with the standard required fields error messages.

For example my page has a 'Project Number', and 'Name' standard required field. If I submit without filling out those fields and also filling it out so my custom error will trigger it pop up "Error: Must give value for Project Number and Name", and say nothing about my errors since the submit doesnt get called. Then if I fill out project number and name, submit does get called and my errors come up "Error with foo checkbox checked you must fill out bar".

So essentially if they leave the 2 standard required fields blank and my 2 custom required fields blank it will stop them at different times with different messages.

I need to call my validation function at the same time the default validation is called but i dont know when/how that is.

1 Answer 1


Validation rules will work on custom fields, as long as those fields are attached to an object. They can also be incredibly complex, assuming you can keep the logic clear enough as you make them more complex. Example of what your validation seems to be in a rule:

   IF ((CheckBox1 == false && 
        CheckBox2 == false),

If the fields are not attached to an object, then you have to build your own system to detect those errors. Heres a link detailed that, or at least, a system very close to how salesforce runs it: http://bobbuzzard.blogspot.com/2011/04/field-level-error-messages-with.html http://bobbuzzard.blogspot.com/2011/04/field-level-error-messages-with_29.html

Hope this helps- although something to note, if you want them all to call at once, and neither of these helps, you could disable validation rules for the page, and simply stack all the errors into a single list of errors, and then render them all at once. That could be more complicated, but is always a solution. Hope this helps!

  • Very helpful I didnt realize how complex rules could be. However, unfortunately my checkboxes arent tied into fields only the textbox so I cant use method #1. 2nd suggestion works, I believe that is how I have it now finding the errors and displaying the message but this still shows the custom errors at a different time then standard validation errors correct? So I suppose I have to go with #3 and just disable validation and then check all required fields myself in my validate() function. Jul 31, 2014 at 17:30
  • Just make sure if you disable validation, to ensure that the rest of your pages or fields which need the validation still have the rules enabled. I would suggest a bit of a hackish solution- having a checkbox on record that when checked, disables the validation rules through a logic check in them. Personally, I dont mind having errors fire at different times, but I can understand how it would hinder the user experience. Good luck! Jul 31, 2014 at 17:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .