Validate Record Data

This trigger validates the record's data using an expression. If the expression results in an error (i.e. a non-null value expected as a string message), the data operation is terminated and an error message is displayed. This is similar to the situation where a field validation fails when creating or modifying a record. To use this trigger, provide a formula expression to validate. The formula returns a string error message when validation fails. It returns an empty string or null if the validation succeeds. For example:

if ({!amount} > 100000) 
   return "Order is too large: {!amount}";
   else
   return null;

Another example:

if ("{!email}" == ""  && "{!phone}" == "") 
   return "Either email or phone must be specified";
   else
   return null;
Note:
  • You can choose the Treat this trigger as a Warning option to allow trigger execution to continue even if there is an error message. In this case, if validation fails at runtime, the user will have a chance to check an Ignore Warning checkbox and proceed with saving data despite the warning. This is similar to custom field validation (see Field validation).
  • The Treat this trigger as a Warning option is executed for UI Record Edit or Delete operations. Other places like Inline editing of list view, Field inline edit (record view page), Mass Update, APIs (updateRecord, setFieldValue) and Import Jobs, the validation trigger directly throws an exception instead of displaying warning message.