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

Catch Validation Error on Record Updates Coming From Outside SF

Hello All,

We have a outside application, which is suppose to update couple records in SF.
Now these records can hit Validation Rule, which prevents the records to save successfully.
Can we have some error traping on these records updates coming from outside of SF, so if they hit the Validation Rule, than shoot an email notification to the admin.
I can read these updates in the Before Trigger, but not sure how to actually catch if they fail to save.
Any help is appreciated.

I don't think you'll be able to do this - when a validation rule is broken, the record save fails and the transaction is rolled back. That would mean that any emails, future calls etc you had queued to send would also be rolled back.  If you can't catch and act on the exception in the external client, the only thing I can think of is to allow the save to complete but mark the record as failed in some way (e.g. checkbox field) and use workflow to send an email alert, then execute an @future call to delete the record.  I wouldn't say its a good solution though.