Apex Triggers handles complex data validation's, we can even make apex trigger handlers are more reusable with setting up custom metadata and custom settings for trigger configurations.
Dynamic field validations in Apex Triggers
From sObject class now we can use addError() method to make field validation's dynamically. See the below example
Account record = new Account();
record.addError('Name','Passing Field Name as String');
addError(FieldAPIName , Error_Message);
By passing fieldName and Error Message to addError method, the validation messages can be displayed at field level instead of hardcoding the field names for Error Message from Apex Trigger's
Review the Working Demo
コメント