Nikita Chursin 2e538ab34c removed mock server | 3 lat temu | |
---|---|---|
app | 3 lat temu | |
config | 4 lat temu | |
scripts | 4 lat temu | |
.forceignore | 4 lat temu | |
.gitignore | 4 lat temu | |
.prettierignore | 4 lat temu | |
.prettierrc | 4 lat temu | |
LICENSE | 4 lat temu | |
README.md | 3 lat temu | |
sfdx-project.json | 4 lat temu |
This library consists of several parts:
Each part is completely independent and can be extracted to use separately.
Trigger Framework is located in app/main/triggerFramework
folder.
To use the framework extend the ATrigger class. The following methods exists to be overriden:
protected override void initialize(List<sObject> records)
protected override void calculate(List<sObject> records)
protected override void validate(List<sObject> records)
protected override void preValidate(List<sObject> records)
protected override void afterInsert(List<sObject> records)
protected override void afterUpsert(List<sObject> records)
protected override void afterUpdate(List<sObject> records)
protected override void validateBeforeDelete(List<sObject> records)
protected override void afterDelete(List<sObject> records)
protected override void afterUndelete(List<sObject> records)
List<sObject> records
parameter is a list of records in a trigger. These are new
records for insert, update, and undelete triggers, and old
records for delete triggers.
There is also a set of helper methods:
protected Boolean isFieldChanged(sObject record, Schema.SObjectField field);
protected Boolean isFieldChangedTo(sObject record, Schema.SObjectField field, Object checkValue);
protected Boolean isFieldChangedFrom(sObject record, Schema.SObjectField field, Object checkValue);
protected sObject getOldRecord(sObject record);
protected Object getOldFieldValue(sObject record, Schema.SObjectField field);
Finally the trigger framework supports partial trigger disablement.
public static void disable(Schema.SObjectType sobjType, TriggerOperation triggerOper);
public static void disableAll(Schema.SObjectType sobjType);
public static void disableAll();
public static void enableAll();
TriggerOperation
here is a standard Salesforce TriggerOperation
enum;
For usage examples take a look at the ATrigger test class.
Another word on tests: I used account object for testing, which may not suite you. In order to change this you need:
app/main/triggerFramework/triggers/TestTrigger.trigger
to you newly created trigger.app/main/triggerFramework/tests/Test_ATrigger.cls
if needed:
java
private static final sObject TEST_RECORD = new Account(Name = 'Test_ATrigger');
private static final String TEST_FIELD_NAME = 'Name';
private static final Object TEST_FIELD_CHANGED_VALUE = 'Changed Name';
Documenting in progress...