2

I have validation rule on a date field that 'Start Date shouldn't preceed today'. I have an trigger which updates another field of the same object. Now when trigger runs on old records field validation fires which stops the field updation. How to by pass this validation.

Regards

1 Answer 1

5

If you want to bypass validation it probably means that your validation logic is not what you need.

For instance "Start Date shouldn't preceed today" only makes sense when the record is created. Of course, old records may and will have an older Start Date. Maybe your validation rule needs to be modified to use the ISNEW () operator so that it only runs when the record is created.

Something like:

AND (ISNEW(), <your existing validation here>)

Another way would be to conditionally disable your rule depending on a custom settings object, which you could disable manually or in your trigger. But that is overthinking it and making it even more complicated. I think that the above approach may be the best for you.

3
  • 1
    What happens if the user tries to update the date field manually which is inline edit, this validation wont fire. But as per business user needs to have the validation. How can we achieve this Apr 28, 2016 at 10:28
  • 1
    But surely, if you don't use the ISNEW(), users will not be able to edit records manually? Because the validation rule will prevent them from saving records, unless they update the Start Date? A workaround could be to compare the started date with the record creation date? Not sure if this is available in a validation rule. If the condition gets too complex, you can always use a trigger as a validation rule, as I described here: salesforce.mkorman.uk/…
    – mkorman
    Apr 28, 2016 at 11:05
  • @Sid It sounds like you need to make start date read-only when the record is being edited. Apr 28, 2016 at 14:18

You must log in to answer this question.

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