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

Trigger the object validation rules

Hi, I have a couple of questions..

1) I have a validation rule setup on the Phone field of the Acct object - that it should be it at least 10 digits. When I'm using a custom controller and have multiple pages to navigate (the second page is to collect contact info), the validation rule isn't fired till I tried to save at the end of the wizard. Is there anyway to fire validation rules before I move to the next page?

2) On the second page, I'm trying to add multiple contacts for a single acct. How do I enforce that I should not be allowed to add more than 5 contacts for a given time. Should I use Javascript or is there way in VF, I can accomplish this...

Please advise.
  1. There is no way to do this with a validation rule until the object is saved.  It's a better user experience to have realtime or pre-second page feedback.  To do that you'll have to either add validation in your PageReference method that sets a field level  / page level error message and returns null or do it via Javascript.  I would recommend the Javascript approach as it will give you a chance to provide a better UX.
  2. How are you adding these additional contacts?  Are you doing Javascript to add additional fields and allowing them to use that?  Are you doing this via VF with a set number of contact fields?  Is this Wizard only for a new account, or is it also runnable on an existing account where there may already be contacts?

Regarding #1, is there any way you could input validations using VF itself without Javascript. 

Regarding#2, I'm not using Javascript. i'm using VF to capture the contacts (using some predefined fields)
You may be able to do it via calling an onchange for each of your fields you need to validate and then do a rerender on a the field to display your error message.  I think you'll be better off doing this via Javascript, because it's easier and more scaleable.

I'm confused as to how you don't know the number of contacts.  If you have it via VF then you should know how many contact informations you have on the page.  Can you include some code to show what you are doing?