Skip to content

A simple and minimal framework for Salesforce Apex triggers management with declarative trigger handlers configuration

License

Notifications You must be signed in to change notification settings

AndreyFilonenko/sfdc-declarative-trigger-framework

 
 

Repository files navigation

Salesforce Apex trigger framework

Example of usage

  1. First, define the settings for AccountTriggerHandler: image

  2. Lets choose beforeInsert and afterInsert methods of AccountTriggerHandler as the targets of test. Also, override the beforeInsert by adding a debug statement:

public class AccountTriggerHandler extends TriggerHandler {
    ...
    public override void beforeInsert() {
        super.beforeInsert();

        System.debug('Overriden beforeInsert method executed!');
    }
}
  1. Next, add some handlers:
public class AccountTriggerHandlerMethod_1 implements Callable {
    public Object call(String action, Map<String, Object> args) {
        List<Account> accounts = (List<Account>)args.get('newList');
        System.debug('AccountTriggerHandlerMethod_1 class executed! ' + accounts.size() + ' records passed. - Should be the first method called');
        return null;
    }
}

public class AccountTriggerHandlerMethod_2 implements Callable {
    public Object call(String action, Map<String, Object> args) {
        List<Account> accounts = (List<Account>)args.get('newList');
        System.debug('AccountTriggerHandlerMethod_2 class executed! ' + accounts.size() + ' records passed.');
        return null;
    }
}

public class AccountTriggerHandlerMethod_3 implements Callable {
    public Object call(String action, Map<String, Object> args) {
        List<Account> accounts = (List<Account>)args.get('newList');
        System.debug('AccountTriggerHandlerMethod_3 class executed! ' + accounts.size() + ' records passed. - Should be the last method called (before all overrides)');
        return null;
    }
}

public class AccountTriggerHandlerMethod_4 implements Callable {
    public Object call(String action, Map<String, Object> args) {
        List<Account> accounts = (List<Account>)args.get('newList');
        System.debug('AccountTriggerHandlerMethod_4 class executed! ' + accounts.size() + ' records passed.');
        return null;
    }
}

public class AccountTriggerHandlerMethod_5 implements Callable {
    public Object call(String action, Map<String, Object> args) {
        List<Account> accounts = (List<Account>)args.get('newList');
        System.debug('AccountTriggerHandlerMethod_5 class executed! ' + accounts.size() + ' records passed.');
        return null;
    }
}
  1. ...and register them as handlers in Custom metadata: image

  2. To trigger the test just execute this in anonymous:

Account acc = new Account();
acc.Name = 'Test';
insert acc;
  1. The results are below: image

All needed classes and example handlers are included in this branch and can be used for other tests.

About

A simple and minimal framework for Salesforce Apex triggers management with declarative trigger handlers configuration

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy