Foundations Apex API Developer Reference

fferpcore.PluggableTriggerApi

global with sharing class PluggableTriggerApi

Provides interfaces that can be used to create plugins to be executed during the trigger of objects shared between multiple packages. Unlike creating multiple triggers, multiple plugins will always be called in a defined order.
To set up a plugin, create a fferpcore__Plugin__mdt record with fferpcore__ExtensionPoint__c of PluggableTriggerApi.PluginConstructor, and fferpcore__ClassName__c which matches an Apex class extending that interface. Plugins will be called in order of the fferpcore__PluginNumber__c field, which should be set to 1 or higher.

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.

global class BillingDocumentTriggerPluginConstructor implements fferpcore.PluggableTriggerApi.PluginConstructor
{
    global Schema.SObjectType sObjectType()
    {
        //This plugin will only be used for Billing Documents.
        return fferpcore__BillingDocument__c.SObjectType;
    }

    global PluggableTriggerApi.Plugin construct(List<SObject> objects, PluggableTriggerApi.Context triggerContext)
    {
        return new BillingDocumentTriggerPlugin(objects);
    }
}

/**
 * An example plugin class that would block billing documents from being deleted.
 */
global class BillingDocumentTriggerPlugin implements fferpcore.PluggableTriggerApi.Plugin
{
    private final List<SObject> m_records;
    public BillingDocumentTriggerPlugin(List<SObject> records)
    {
        m_records = records;
    }

    global void onBeforeInsert() {}

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

    global void onBeforeDelete() {}

    global void onAfterInsert() {}

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

    global void onAfterDelete()
    {
        for (SObject record : m_records)
        {
            record.addError('Cannot delete billing documents');
        }
    }

    global void onAfterUndelete() {}
}

fferpcore.PluggableTriggerApi.Plugin

global interface Plugin

Interface that plugins should extend. The objects being processed by the trigger should be stored on instances extending this interface.

Methods

onBeforeInsert

void onBeforeInsert()

Override this to perform processing during the before insert phase.

onBeforeUpdate

void onBeforeUpdate(Map<Id, SObject> existingRecords)

Override this to perform processing during the before update phase.

Input Parameters

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

onBeforeDelete

void onBeforeDelete()

Override this to perform processing during the before delete phase.

onAfterInsert

void onAfterInsert()

Override this to perform processing during the after insert phase.

onAfterUpdate

void onAfterUpdate(Map<Id, SObject> existingRecords)

Override this to perform processing during the after update phase.

Input Parameters

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

onAfterDelete

void onAfterDelete()

Override this to perform processing during the after delete phase.

onAfterUndelete

void onAfterUndelete()

Override this to perform processing during the after undelete phase.

fferpcore.PluggableTriggerApi.PluginConstructor

global interface PluginConstructor

Constructs a plugin during a particular trigger execution. This is responsible for deciding whether a plugin is appropriate to the current trigger, and passing trigger context to the plugin being created.

Methods

sObjectType

Schema.SObjectType sObjectType()

Used to select only plugins that are relevant to the records in the trigger.

Return Value

The sobject type that this plugin should be applied to.

construct

PluggableTriggerApi.Plugin construct(List<SObject> objects, fferpcore.PluggableTriggerApi.Context triggerContext)

Called at the start of the trigger execution to construct plugins that will be applied.

Input Parameters

Name Type Description
objects List<SObject> The records being modified in the current trigger execution.
triggerContext fferpcore.PluggableTriggerApi.Context Stores any additional context for the current trigger execution.

Return Value

A plugin that will operate on the given sobjects when called.

fferpcore.PluggableTriggerApi.Context

global virtual with sharing class Context

Additional information regarding the trigger context that the plugin is being called in. Currently unused, but in place for later expansion.

© Copyright 2009–2022 FinancialForce.com, inc. All rights reserved. Various trademarks held by their respective owners.