Foundations Apex API Developer Reference

fferpcore.PluggableTrigger

global inherited sharing class PluggableTrigger extends fflib_SObjectDomain

A domain class for an Apex trigger which executes any pluggable triggers (classes implementing PluggableTriggerApi.Plugin). It is intended to be instantiated from an Apex trigger with the methods invoked according to the trigger operation, for example, onBeforeInsert() when Trigger.OperationType equals BEFORE_INSERT.
See fferpcore.PluggableTriggerApi for more information.

Sample Code

//Note: This sample code is for demonstration purposes only. It is not intended for
//use in a production environment, is not guaranteed against defects or errors, and
//is in no way optimized or streamlined.

trigger BillingDocumentTrigger on BillingDocument__c(
    before insert,
    before update,
    before delete,
    after insert,
    after update,
    after delete,
    after undelete
) {
    List<SObject> domainRecords;

    switch on Trigger.operationType {
        when BEFORE_DELETE, AFTER_DELETE {
            domainRecords = Trigger.old;
        }
        when else {
            domainRecords = Trigger.new;
        }
    }

    try {
        fferpcore.PluggableTrigger target = new fferpcore.PluggableTrigger.Constructor().construct(domainRecords);

        switch on Trigger.operationType {
            when BEFORE_INSERT {
                target.onBeforeInsert();
            }
            when AFTER_INSERT {
                target.onAfterInsert();
            }
            when BEFORE_UPDATE {
                target.onBeforeUpdate();
            }
            when AFTER_UPDATE {
                target.onAfterUpdate();
            }
            when BEFORE_DELETE {
                target.onBeforeDelete();
            }
            when AFTER_DELETE {
                target.onAfterDelete();
            }
        }
    } catch (Exception e) {
        for (SObject record : domainRecords) {
            record.addError(e);
        }
    }
}

Methods

PluggableTrigger

global PluggableTrigger(List<SObject> sObjectList, List<fferpcore.PluggableTriggerApi.Plugin> plugins)

Construct this domain class.

Input Parameters

Name Type Description
sObjectList List<SObject> The SObject records from the Apex Trigger.
plugins List<fferpcore.PluggableTriggerApi.Plugin> The pluggable triggers to apply the SObject records.

onBeforeInsert

global override void onBeforeInsert()

Invokes onBeforeInsert() on each pluggable trigger.

runTriggerHandler

global static void runTriggerHandler()

Invokes the triggerHandler for the pluggable trigger. This method is directly callable.

onBeforeUpdate

global override void onBeforeUpdate(Map<Id, SObject> existingRecords)

Invokes onBeforeUpdate() on each pluggable trigger.

Input Parameters

Name Type Description
existingRecords Map<Id, SObject> The records as they were before the current update.

onBeforeDelete

global override void onBeforeDelete()

Invokes onBeforeDelete() on each pluggable trigger.

onAfterInsert

global override void onAfterInsert()

Invokes onAfterInsert() on each pluggable trigger.

onAfterUpdate

global override void onAfterUpdate(Map<Id, SObject> existingRecords)

Invokes onAfterUpdate() on each pluggable trigger.

Input Parameters

Name Type Description
existingRecords Map<Id, SObject> The records in their final state, allowing validation.

onAfterDelete

global override void onAfterDelete()

Invokes onAfterDelete() on each pluggable trigger.

onAfterUndelete

global override void onAfterUndelete()

Invokes onAfterUndelete() on each pluggable trigger.

fferpcore.PluggableTrigger.Constructor

global inherited sharing class Constructor implements fflib_SObjectDomain.IConstructable

Responsible for finding and constructing any pluggable triggers.

Methods

Constructor

global Constructor()

construct

global fferpcore.PluggableTrigger construct(List<SObject> objects)

Constructs the pluggable triggers.

Input Parameters

Name Type Description
objects List<SObject> Provides SObject records from the trigger. For delete operations, this is typically the value of Trigger.old. For other operations, this is typically the value of Trigger.new.
© Copyright 2009–2024 Certinia Inc. All rights reserved. Various trademarks held by their respective owners.