TRG_ExecuteValidationRules
Class · Group: Validation
Learn it: Fast Start - Custom Validations and Validation guide
global inherited sharing class TRG_ExecuteValidationRules extends TRG_Base implements IF_Trigger.BeforeInsert, IF_Trigger.AfterInsert, IF_Trigger.BeforeUpdate, IF_Trigger.AfterUpdate, IF_Trigger.BeforeDelete, IF_Trigger.AfterDelete, IF_Trigger.AfterUndeleteExtends: TRG_Base
Implements: IF_Trigger.BeforeInsert, IF_Trigger.AfterInsert, IF_Trigger.BeforeUpdate, IF_Trigger.AfterUpdate, IF_Trigger.BeforeDelete, IF_Trigger.AfterDelete, IF_Trigger.AfterUndelete
Known Derived Types: IF_Trigger.AfterDelete.afterDelete(List<SObject>), IF_Trigger.AfterInsert.afterInsert(List<SObject>), IF_Trigger.AfterUndelete.afterUndelete(List<SObject>), IF_Trigger.AfterUpdate.afterUpdate(List<SObject>,List<SObject>), IF_Trigger.BeforeDelete.beforeDelete(List<SObject>), IF_Trigger.BeforeInsert.beforeInsert(List<SObject>), IF_Trigger.BeforeUpdate.beforeUpdate(List<SObject>,List<SObject>)
Pre-built trigger action that executes formula-driven validation rules. This class implements all trigger interfaces and automatically executes validation rules configured via ValidationRuleGroup__mdt and ValidationRule__mdt for the current trigger context. Setup in your org: Create TriggerSetting__mdt for your object (if not already exists) Create TriggerAction__mdt pointing to kern.TRG_ExecuteValidationRules Configure ValidationRuleGroup__mdt linked to your TriggerSetting Create ValidationRule__mdt records with formulas and error messages
Example
// TriggerAction__mdt configuration (no code required)
DeveloperName: Execute_Account_Validation_Rules
MasterLabel: Execute Account Validation Rules
ApexClassName__c: kern.TRG_ExecuteValidationRules
TriggerSetting__c: Account_Trigger_Setting
Event__c: Before Insert
Order__c: 10
Description__c: Executes formula-driven validation rules for Account recordsSee Also: UTIL_ValidationRule, ValidationRuleGroup__mdt, ValidationRule__mdt
Methods
| Method | Description |
|---|---|
| global void afterDelete(List<SObject> oldRecords) | Checks the deleted records against the After Delete validation rules set up for their object. |
| global void afterInsert(List<SObject> newRecords) | Checks the saved records against the After Insert validation rules set up for their object. |
| global void afterUndelete(List<SObject> newRecords) | Checks the restored records against the After Undelete validation rules set up for their object. |
| global void afterUpdate(List<SObject> newRecords, List<SObject> oldRecords) | Checks the saved records against the After Update validation rules set up for their object. |
| global void beforeDelete(List<SObject> oldRecords) | Checks the records about to be deleted against the Before Delete validation rules set up for their object. |
| global void beforeInsert(List<SObject> newRecords) | Checks the new records against the Before Insert validation rules set up for their object. |
| global void beforeUpdate(List<SObject> newRecords, List<SObject> oldRecords) | Checks the changed records against the Before Update validation rules set up for their object. |
afterDelete
global void afterDelete(List<SObject> oldRecords)Checks the deleted records against the After Delete validation rules set up for their object. A failed rule of Error severity rolls the delete back and shows its message on the record. A failed Warning rule, or a rule with Shadow Mode turned on, is only logged.
Parameters
| Parameter | Type | Description |
|---|---|---|
oldRecords | List | The list of deleted records |
Example
instance.afterDelete(records);afterInsert
global void afterInsert(List<SObject> newRecords)Checks the saved records against the After Insert validation rules set up for their object. A failed rule of Error severity rolls the save back and shows its message on the record. A failed Warning rule, or a rule with Shadow Mode turned on, is only logged.
Parameters
| Parameter | Type | Description |
|---|---|---|
newRecords | List | The list of newly inserted records |
Example
instance.afterInsert(records);afterUndelete
global void afterUndelete(List<SObject> newRecords)Checks the restored records against the After Undelete validation rules set up for their object. A failed rule of Error severity rolls the restore back and shows its message on the record. A failed Warning rule, or a rule with Shadow Mode turned on, is only logged.
Parameters
| Parameter | Type | Description |
|---|---|---|
newRecords | List | The list of undeleted records |
Example
instance.afterUndelete(records);afterUpdate
global void afterUpdate(List<SObject> newRecords, List<SObject> oldRecords)Checks the saved records against the After Update validation rules set up for their object. A failed rule of Error severity rolls the save back and shows its message on the record. A failed Warning rule, or a rule with Shadow Mode turned on, is only logged.
Parameters
| Parameter | Type | Description |
|---|---|---|
newRecords | List | The list of records with new values |
oldRecords | SObject | The list of records with old values |
Example
instance.afterUpdate(records, records);beforeDelete
global void beforeDelete(List<SObject> oldRecords)Checks the records about to be deleted against the Before Delete validation rules set up for their object. A failed rule of Error severity stops the delete and shows its message on the record. A failed Warning rule, or a rule with Shadow Mode turned on, is only logged.
Parameters
| Parameter | Type | Description |
|---|---|---|
oldRecords | List | The list of records to be deleted |
Example
instance.beforeDelete(records);beforeInsert
global void beforeInsert(List<SObject> newRecords)Checks the new records against the Before Insert validation rules set up for their object. A failed rule of Error severity stops the save and shows its message on the record. A failed Warning rule, or a rule with Shadow Mode turned on, is only logged.
Parameters
| Parameter | Type | Description |
|---|---|---|
newRecords | List | The list of new records to validate |
Example
instance.beforeInsert(records);beforeUpdate
global void beforeUpdate(List<SObject> newRecords, List<SObject> oldRecords)Checks the changed records against the Before Update validation rules set up for their object. A failed rule of Error severity stops the save and shows its message on the record. A failed Warning rule, or a rule with Shadow Mode turned on, is only logged.
Parameters
| Parameter | Type | Description |
|---|---|---|
newRecords | List | The list of records with new values |
oldRecords | SObject | The list of records with old values |
Example
instance.beforeUpdate(records, records);