[SalesForce] can a validation rule be set up to fire when a record is created

1) When I create a new contact on an account and a field has a certain value, a checkbox on the new contact is automatically checked. If that is checked I need to force the user to fill another field.

2) I have a validation rule in place that is working for already created records when they are edited and that particular field is checked and the field I need to require is blank that is working.

How do I ensure that the user fills in the field on a new record. I don't want them to be able to save without filling in the field.

Best Answer

Validation rules fire early in the process; if you're using a workflow rule or process builder to check the box, it's already too late for the validation rule to take effect. See the Triggers and Order of Execution document.

If the record was updated with workflow field updates, fires before update triggers and after update triggers one more time (and only one more time), in addition to standard validations. Custom validation rules, duplicate rules, and escalation rules are not run again. (Emphasis added.)

So, if you intend to have the box be checked, include this in your validation rules. There would be two rules: one to force the user to check the box, and one to force the user to populate the other field. You could also do this in an Apex Trigger if you wanted to, but I generally prefer a clicks-not-code approach when possible.

Related Topic