• 1Installation
  • 2Preliminary Knowledge
  • 3Create Triggers
  • 4Trigger Handler
  • 5Bulk Object
  • 6Find Specific Objects
  • 7Data Sharing
  • 8Catch All Events
  • 9Trigger Controller
  • 10Normal Trigger Event Handler
  • 11Trigger Context
  • 12Unit Test
  • 13Take Only Trigger Execution

Trap.apex

  • Docs
  • Tutorials
Getting started with Trap.apex

Trigger Handler

The next step is to create your trigger handler, which encapsulates logic separately from the trigger.

public with sharing class CaseTrigger extends Trap.TriggerHandler {
    public override void setUpBeforeInsert(Trap.BulkObject bulkObj) {
        bulkObj.newStream
            .filter(new CustomFilterFunc())
            .subscribe(Trap.F.addError.apply('test error'));
    }
}

Compared with other trigger frameworks, it is similar that we have separate trigger events to process the business logic. Different is that we set up the streams in the bulk object to do the process. For more information, please check out Stream.apex.

The trigger handler is located by naming convertion, adding 'Trigger' to the name of the SObject type. You can configure this behavior, though.

Done