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
sfdcbynitesfdcbynite 

add an error to a field when I have its Schema.SObjectField token

I am making an attempt at using server-side validation for a VF form. I have my validation rules set up. But the problem, as we all know, is that only the first error is displayed. Not good if there are a number of errors. So there is this solution from Bob Buzzard: http://bobbuzzard.blogspot.com/2011/04/field-level-error-messages-with.html But it requires hard coding the fields. Also not ideal as fields, and their validation may change. So I want to use some dynamic apex for this. I saw that DMLException has a getDMLFields() which returns a list of SObjectField tokens for the fields in error. But I haven't yet figured out how to get a handle to the actual instance of the field in order to call the .addError() method. So anybody know how to get a handle to the instance of the field? Or a better solution to the problem? Thanks, Dovid